当前位置:网站首页>What is the difference between JS undefined and null

What is the difference between JS undefined and null

2022-06-23 03:01:00 It workers

stay JavaScript in ,undefined Indicates that a variable has been declared but has not been assigned , for example :

var TestVar;
alert(TestVar); // Show undefined
alert(typeof TestVar); // Show undefined

null It's assignment . It can be assigned to variables as a representation of no value :

var TestVar = null;
alert(TestVar); // Show  null
alert(typeof TestVar); // Show object

As can be seen from the previous example ,undefined and null There are two different types :undefined Is itself a type ( Undefined ), and null It's an object .

null === undefined // false
null == undefined // true
null === null // true
null = 'value' // ReferenceError
undefined = 'value' // 'value'
原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201251849418991.html