What is the difference between null and undefined in JavaScript?

前端 未结 30 3280
夕颜
夕颜 2020-11-21 23:06

I want to know what the difference is between null and undefined in JavaScript.

30条回答
  •  孤独总比滥情好
    2020-11-21 23:29

    Both Null and undefined in JavaScript indicate absence of value.

    var a = null; //variable assigned null value
    var b;  // undefined
    

    Despite the fact both exist for absence of value but: Undefined actually means the variable is not initialized. Functions that return nothing and function parameters for which no value is supplied, undefined value is returned. Use strict equality operator === to distinguish between null and undefined.

    Reference: http://www.thesstech.com/javascript/null-and-undefined

提交回复
热议问题