DEV Community

Discussion on: There's no "else if" in JS

Collapse
 
mahlongumbs profile image
Mahlon Gumbs

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.

Collapse
 
qm3ster profile image
Mihail Malo

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