首页 > 解决方案 > Why this expression is var a = 3, b = a = typeof b; giving 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

标签: javascript

解决方案


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

推荐阅读