This expression is giving me the undefined
output in this console.
Please help to understand why it is printing undefined
?
var a = 3, b = a = typeof b; // undefined
This expression is giving me the undefined
output in this console.
Please help to understand why it is printing undefined
?
var a = 3, b = a = typeof b; // undefined
What really happens here is:
var a = 3; // so a gets a value.
var b; // var b exists but is undefined.
a = typeof b; // a receives type of b, which is undefined at this time
b = a; // b gets the value from a
An assignment operator assigns a value to its left operand based on the value of its right operand. That is, a = b assigns the value of b to a.
Thus, in our case
b = a = typeof b;
a gets the value undefined and then b.
var a=3, b = a = typeof b;
undefined
a
"undefined"
b
"undefined"