Would like to understand: return (current > prev) ? current : prev;

I was viewing the intermediate code solution on freeCodeCamp Algorithm Challenge Guide: Return largest Numbers in Arrays and noticed the unusual notation style used on the innermost return statement (current > prev) ? current : prev;. Can anyone explain it to me? Thank you in advance.

2 Likes

It’s a ternary operator. It is a shorthand of if else.

If the condition is true, it returns current else prev.

1 Like

Ah yes. The link for ternary operators is provided. JavaScript Ternary Operator

1 Like