To say Null first, it represents a special value that is commonly used to describe "null values." Performs a typeof operation on NULL, and the result returns the string "Object", which means that null can be considered a special object value, meaning "Non-object" (It feels strange). In fact, it is generally assumed that NULL is the only member of its own type, and it can represent numbers, strings, and objects as "no value".
JavaScript also has a second value to indicate the value of the vacancy, that is, undefined, with undefined values to represent a deeper "null value." Undefined appears in 4 cases: ① variable declaration But no initialization ② the object property or array element does not exist ③ if the function does not have any return value, then the value of the Undefined④ reference function parameter that does not provide the argument is undefined only.
The two are the same: ① as mentioned earlier, they are all "false values", meaning that JavaScript expects to use a Boolean value, they are converted to False;② none of the two contain any properties and methods.
The difference: ①null is a keyword in the JavaScript language, and undefined is a predefined global variable for JavaScript, not a keyword. And, in ECMAScript 3, undefined is a readable, writable variable that can be assigned any value, and this error is corrected in ECMAScript 5. In this version of undefined is read-only (see the internet said that now the browser is basically supporting the ECMAScript 5, I do not know why I in the browser to assign a value of undefined no error, just did not change its value); ② performs typeof operations, NULL returns " Object string, undefined returns the "undefined" string.
As for comparing null with undefined, NULL = = undefined returns true,null = = undefined returns false. You can think of undefined as a vacancy for a system-level, unexpected, or error-like value, and Null is a vacancy representing a program-level, normal, or expected value. If you want to assign them to a variable or property, or pass in a function as a parameter, it is best to choose to use NULL.
The above mentioned is the entire content of this article, I hope you can enjoy.