Bracket placement question

why does this work

let tst = "hey";

if (tst) {

  console.log("1")

}

else (tst === 'hey')  

{

 console.log("2")  

};

but this doesn’t

let tst = "hey";

if (tst) {

  console.log("1")

}

else (tst === 'hey')  {

 console.log("2")  

};

Hello. The first one works because you have two line breaks between the else and the console.log. As a general rule, you shouldn’t have else (condition), but instead you should use else if (condition).
I hope this helps!

1 Like