+ 4

JavaScript Help!

Hello, can someone explain the code I made earlier. I expect error on both cases but why it doesn't. I already finished JavaScript course but still noob at these things. 🤦‍♀ Please someone explain these to me. https://code.sololearn.com/WxS2SrLMpXJj/?ref=app

17th Jun 2019, 1:13 PM
Nootnoot
Nootnoot - avatar
3 Réponses
+ 3
myVar && someUndeclaredVariable If myVar is false then someUndeclaredVariable is not checked (since the output would be false even if someUndeclaredVariable is true) So since the condition becomes false in this case it doesn't through an error But if myVar is true then someUndeclaredVariable is checked u have to initialize someUndeclaredVariable otherwise it would be undefined ( which is false when used for checking condition with && operator)
17th Jun 2019, 1:54 PM
Tony Stark
Tony Stark - avatar
+ 3
Oh so the if the first condition returns false, then the interpreter ignores the second condition when using AND operator... is that right??? Btw thank you sir.
17th Jun 2019, 2:06 PM
Nootnoot
Nootnoot - avatar
+ 3
Exactly
17th Jun 2019, 2:07 PM
Tony Stark
Tony Stark - avatar