Maximum function challenge

if, while, switch are conditional statements, but their argument takes an expression. Compare this to a return statement. It too can only take an expression. We cannot return a statement, only a value.

expression  => value
statement   => flow
conditional => contol flow

Consider a ternary. It can be both statement and expression. How’s that? By assignment.

return a ? a : null;

Here we still have a return statement, but the value is a ternary expression. Some might call this a ternary statement. Notice that return is a sort of assignment? It assigns the value to the variable furnished by the caller.

a = func()
1 Like

Addendum

Switchs are cool conditional statements because they have two arguments, not one.

 > a = Math.floor(Math.random() * 10)
<- 7
 > switch(a) {
       case 3 + 4: console.log('3 + 4 = 7'); break;
       default: console.log(a);
   }
   3 + 4 = 7
<- undefined
 > 
 > a = Math.floor(Math.random() * 10)
<- 8
 > switch(a) {
       case 3 + 4: console.log('3 + 4 = 7'); break;
       case 3 + 5: console.log('3 + 5 = 8'); break;
       default: console.log(a);
   }
   3 + 5 = 8
<- undefined
 >