loading...

re: There's no "else if" in JS VIEW POST

FULL DISCUSSION
 

Cool point. In cases like this, I often forgo the else altogether because of the return statements.

function wow(arg){

  if(arg === "dog") return "LOVELY";

  if(arg === "cat") return "CUTE";

  return "gimme an animal";
}

wow("cat");

Still, your point about understanding the why behind what we write is an important one. Thanks for sharing.

 

A function with only ifs that return is just the missing-from-JS pattern matching+guards syntax.

code of conduct - report abuse