+ 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
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)
+ 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.
+ 3
Exactly