I am experimenting with this malicious JavaScript string: var undefined = true;
Each uninitialized variable in JavaScript has an undefined value, which is simply a variable that contains the special value 'undefined' , so the following should execute alert :
var undefined = true, x; if (x) { alert('ok'); }
But this is not so, and my question is why?
In further experiments, I tried the following:
var undefined = true, x = undefined; if (x) { alert('ok'); }
This time alert is executed.
So my question is ... because the first fragment of x contains undefined (because it is not initialized), why didnβt it execute the alert ? The strange thing is that when I explicitly declare that x is undefined ( x = undefined ), an alert is executed ...
javascript
Andreas Grech
source share