Home > Web Front-end > JS Tutorial > JavaScript Undefined, the difference between Null type and NaN value_Basic knowledge

JavaScript Undefined, the difference between Null type and NaN value_Basic knowledge

WBOY
Release: 2016-05-16 18:59:41
Original
1118 people have browsed it
One Undefined type
There is only one value undefined
The return type of typeof is undefined in the following three cases
1. When the variable is not initialized
2. When the variable is undefined
3. When the function has no clear return value (when the function does not return a value, it returns undefined)
undefined is not equivalent to an undefined value
typeof does not really distinguish whether it is undefined or not
See below Sample code:
var oTemp;
alert(typeof oTemp); // outputs "undefined"
alert(typeof oTemp2); // outputs "undefined"
alert(oTemp2 == undefined ); // Error oTemp2 is undefined and cannot be used for other operations except typeof.
When the variable
has two Null types
there is only one null, and undefined is derived from null. , so undefined == null
undefined is the variable that has been declared but not initialized.
null represents an object that does not yet exist.
Three NaN values ​​
is a special value. Represents Not a Number
If the type conversion fails, NaN will be returned
e.g. If you want to convert a word blue into a numerical value, it will fail because there is no equivalent value
NaN is not equal to itself
That is NaN == NaN is false
To determine NaN, use isNaN();
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template