[TIL] null, undefined, undeclared 차이점

ShallWeDance·2021년 7월 23일
0

TIL

목록 보기
1/17
post-thumbnail

JavaScript에서 null, undefined 그리고 undeclared는 무슨 차이가 있을까?

null

null은 값이 비어있거나 존재하지 않는 값을 참조했을 때 사용되는 원시 값, type은 object다.

undefined

변수가 선언되었지만 아직 값이 할당되지 않았을 때 사용되는 변수, type은 undefined 라는 type을 가진다.


console.log();type of를 사용해서 undefined나 null을 체크할 수 있다.

+undeclared

var 키워드 없이 선언된 변수이다.

Reference

What’s the difference between a variable that is: null, undefined or undeclared?

0개의 댓글