Ternary conditional returns unexpected token error


#1

Probably a dumb question but why does this work?

function isGreaterThan(numberOne, numberTwo){
if(numberOne > numberTwo) {
return true;
} else {
return false;
}
}

console.log(isGreaterThan(4, 6));

and this return an unexpected token error?

function isGreaterThan(numberOne, numberTwo) {
numberOne > numberTwo ? return true : return false;
};

Do ternary conditionals not work with parameter?


#2

expressions can’t contain statements, statements can’t be evaluated for a result

For example, addition requires two values, if you only have ONE value because the other value isn’t a value at all, then you have a problem

5 + (return 6) <-- doesn't make sense


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.