0
Why this code results in NaN?
var x = 4; var y = 5; var d = 4 + z; var z = y - x; var c = x+z+d+y; alert(c);
10 Respuestas
+ 5
DO NOT PUT CODE IN THE TITLE SECTION. Put it in the description part or link it.
+ 5
"z" has not been defined when using it in line 3, 4 + undefinded is not a number.
In strict mode, this code may not work.
edit: Seems to work in strict mode.
+ 3
Keep in mind. Code in JavaScript is read and executed from top to bottom, following the order in which it appears in the script.
+ 1
at the time "d" is declared, "z" is not defined yet, resulting in undefined, this makes any calculation on it worthless (still results in undefined)
0
Probably using Z before it's defined.
But var accepts hoisting so the result should result 15.
0
OK Lisa
0
Strict mode?
0
Umer
In 3rd statement you didn't even defined z variable and using it for sum. You have define it later.
And what you even mean by strict mode?
0
Try using
alert(int(c));