[JavaScript] Truthy or Falsy values

Chaeeun Lee·2023년 7월 29일

falsy 값

  • 0
  • "" : 빈 문자열
  • undefined
  • null
  • NaN
let height

if(heigt){
	console.log("height is defined")
} else {
	console.log("height is undefined")
}

Q1. else 문이 실행된 이유?
A1. heigt의 값이 undefined이기 때문이다.

! 여기서 주의
만약에 height0을 할당해도 else문이 실행된다. 0은 falsy값이기 때문이다.

profile
나는야 뚝딱이 개발자야

1개의 댓글

comment-user-thumbnail
2023년 7월 29일

감사합니다. 이런 정보를 나눠주셔서 좋아요.

답글 달기