Why i can't use the "return" keyword inside a ternary operator?

For example, the following code:

const plantNeedsWater = function(day){
  day === 'Wednesday' ? return true : return false;
}

Results in a syntax error. Why is that?

Just wrap the whole ternary in a return statement and you’re golden:

const plantNeedsWater = (day) => {
  return (day === 'Wednesday' ? true : false);  
};

console.log(plantNeedsWater("Wednesday"));
//true

2 Likes