+ 1

Javascript: "undefined" == undefined ??

var a; var b = "undefined"; alert(typeof a == b); // true Could anyone explain me why is it true? For my understanding, a is an undefined variable and b is a string with an existing value that happens to be "undefined".

25th Sep 2020, 5:32 PM
Prof. Dr. Zoltán Vass
3 ответов
+ 5
A typeof always returns a string, that's the reason why typeof a == b(when b is assigned a string value "undefined") is true. And also "undefined" != undefined. "undefined" == string, while undefined == special data type.
25th Sep 2020, 6:17 PM
Infinite
Infinite - avatar
25th Sep 2020, 6:58 PM
Prof. Dr. Zoltán Vass