null represents a "null" value, which is the same as 0 and the empty string '' is different, 0 is a numerical value, '' means the length is # A string of ##0, while null means "empty".
In other languages, there are also expressions similar to JavaScript's null, such as Java also uses null, Swift uses nil, Python uses None means. However, in JavaScript, there is also a null similar to undefined, which means "Undefined".
The designers of JavaScript hope to use null to represent an empty value, and undefined means the value is undefined. Facts have proved that this is of no use, and the difference between the two is of little significance. In most cases, we should use null.
*undefined is only useful when determining whether function parameters are passed.
The above is the detailed content of What is the original design intention of null and undefined in js. For more information, please follow other related articles on the PHP Chinese website!