The data type

Basic data types: number, String, Boolean, NULL, undefined
Reference data types: function, Object, Array

The difference between

Null means that an object is defined and has a value of “null”.

Undefined means the value does not exist

typeof undefined //"undefined" 
Copy the code

Undefined is a primitive value that means “nothing” or “missing value”, that is, there should be a value here, but it’s not defined yet. Returns undefined when attempting to read

For example, if a variable is declared but not assigned, it equals undefined

typeof null //"object" 
Copy the code

Null is an object (empty object, without any properties or methods)

For example, as an argument to a function, indicating that the function’s argument is not an object

Note: It is important to use === when validating null, because == cannot indicate “missing value”, i.e. there should be a value here, but it has not been defined yet.

Typical usage:

1. If a variable is declared but not assigned, it is undefined

2. When the function is called, the argument that should be provided is not provided, which is equal to undefined

3, the object has no assigned attribute, the value of this attribute is undefined

4. If the function returns no value, undefined is returned by default

Null means “no object”, meaning there should be no value. Typical usage:

4.1 as parameters of a function, it means that the parameters of the function are not objects

4.2. As the end of the object prototype chain