본문 바로가기

Javascript Tips

js tip) 0 혹은 ""(빈칸) 체크 하기

728x90

js에서 0 혹은 빈칸을 체크하려면 다음과 같다.

let a = 0;
let b = "";

console.log(a == 0); //true
console.log(b == 0); //true

if (b) {
	console.log('b는 들어있다 !');
} else if (!b) {
	// 여기가 출력!
	console.log('b는 들어있지 않다. !');
}

 

 

동등연산자로 0으로 비교하면

빈칸과 0을 한번에 체크가 가능하다