What are the five null values of javascript?
Most people do not understand the knowledge points of this article "what are the five null values of javascript?", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article "what are the five null values of javascript?"
There are five null values in javaScript, which are "false", "null", "undefined", "and" 0 "; their corresponding data types are" boolean "," object "," undefined "," String ", and" number ".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
There are five kinds of null and false values in javaScript, which are false,null,undefined, "", and 0, respectively. In a broad sense, these five values are invalid or null values of the corresponding data type.
What these five values have in common is that the false branch is executed when the if statement is executed and the true branch is executed when the corresponding non-statement is executed.
1 、 undefined
In javaScript, undefined is derived from null, and the browser default variable is undefined when initializing. Code example:
Var str;alert (str); / / undefined
In addition,
If (undefined = = null) {alert ("undefined = = null is true");}
Pop-up: undefined = = null is true
2 、 null
Null represents an object that does not exist. Code example:
Var obj = document.getElementById ("btn"); alert (obj); / / null
Although the type of null is object, null does not have the properties of an object. We cannot perform default calls to object instances such as null.toString (), null.constructor, etc.
The execution result of null = = undefined is true. In addition, the variable is assigned to null to facilitate garbage collection.
3. "", 0.false
Zero false is represented as a false value in the if statement, but they are all meaningful data and are only used as null or false values.
".toString (), (0) .toString (), false.toString () are all legal executable statements.
In addition,
If (0 = = []) {alert ("0 = = [] is true");} if (0 = ='') {alert ("0 = =''is true");} if (0 = = false) {alert ("0 = = false is true");}
The browser pops up in turn:
0 = = [] is true0 =''is true0 = = false is true
And
If ("" = = false) {alert ('"= = false is true');}
Browser pop-up:
"" = = false is true
Five types of null values for js:
Typeof (undefined) = = 'undefined'
Typeof (null) = = 'object'
Typeof ("") = = 'String'
Typeof (0) = = 'number'
Typeof (false) = = 'boolean'
The above is the content of this article on "what are the five null values of javascript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.