null and undefined in javascript

1. undefined and null are automatically converted to false in boolean arithmetic.

 

2. null == undefined;//true

   null === undefined;//false


2. typeof null;//object

  typeof undefined;//undefined

 

3. Number(null);//0

    Number(undefined);//NaN

4. Current usage:
null means "no object", i.e. there should be no value here. Typical usage:
(1) As a parameter of a function, it means that the parameter of the function is not an object.
(2) As the end point of the object prototype chain.
Object.getPrototypeOf(Object.prototype);//null


undefined means "missing value". Typical usage:
(1) When a variable is declared and has not been assigned a value, the variable is equal to undefined.
var data;
data;//undefined
(2) When the function is called, the parameter that should be provided is not provided, and the parameter is equal to undefined.
function f(data){console.log(data);}
f();//undefined
(3) The object has no assigned property, and the value of this property is undefined.
var obj = new Object();
obj.p;//undefined
(4) When the function does not return a value, it returns undefined by default.
var res = (function(){})();//undefined

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325230027&siteId=291194637