Undefined represents the value when the variable is declared but not initialized.
Null means that the object is ready to be saved, and the value of the object is not actually saved. From a logical point of view, a null value represents an empty object pointer.
There are 5 basic types of JavaScript (ECMAScript Standard): Undefined, Null, Boolean, number, String, and a complex type object. You can see that null and undefined belong to different types, uninitialized defined values are detected by typeof as "undefined" (strings), and null values are detected by TypeOf as "Object" (String).
It is not recommended to explicitly set a variable to undefined at any time, but if the variable that holds the object does not actually hold the object, it should be set to null.
In fact, the undefined value is derived from a null value, and the ECMAScript standard specifies that the test for equality should return true, that is,
alert (null==undefined); True
The difference between null and undefined