Diffenrences between ‘null’ and ‘undefined’

JIEUN YANG·2023년 2월 20일
0

In Javascript, there could be comparison logics to differenciate ‘null’ from ‘undefined’.
‘undefined’ is a state when valiables are declared but have no value.
‘null’ is a state when valiables are declared but allocate emtpy value.

For example, when the response of requesting Http has no specific property, it is evaluated as undefined
But, Unlike undefined, null shows when there are no values explicitly

const { data } = Axios.get('https://github.com.test')
console.log(data) // {customer : 'yang', address : null, 
// itemList : [{itemName : 'candy', itemQty : 2, errorCode : 300101, errorRemark : 'no matched item']}

console.log(data.zipCode) // undefined

typepf null // 'object'
typeof undefined // 'undefined'
null === undefined // false
null == undefined // true

How does the ‘null === undefined’ statement come out?
The answer is false

Because ‘null’ is set as the value to exactly indicate “no value” while ‘undefined’ is that when properties don’t exist or valiable desn’t have value.

Also, typeof null evaluates “object”. On the other hand, undefined evalutes “undefined”

To long story short,
null’ and ‘undefined’ are different in some reasons as mentioned above.

profile
violet's development note

0개의 댓글