+ 1
JavaScript: variable without value outputs 1
Anyone explaining this simple code? var x; if (x = 1) { alert("1"); } else { alert("2"); } // output: 1
4 Respostas
+ 7
Prof. Dr. Zoltán Vass Thank you for your opinion! I'm glad to hear that! 😃
Also, thanks for you noticed me about the Line 9. Well, yes, it's actually redundant.. 😁
+ 6
Welcome.
Take a look on this code, i tried to write the things. Maybe the answer can be explained better than mine, but at least this code is working :)
https://code.sololearn.com/WSxyh2kBdQ9h/?ref=app
+ 4
In your first if statement you are DEFINING x as 1. Use the == to compare x to 1.
+ 1
Donthack Thanks for the code, it is a nice explanation! (BTW line 9 in your code seems to be redundant)