mini목차: 1. 개념 되짚기 2. 조별과제+토론 3. 플러스알파

1. 개념 되짚기

3. 플러스알파: JS에서의 자료형 알쓸신잡 (스터디시간에 진행)

console.log(true==1) //true
console.log(true=="1") //true
console.log(1=="1") //true

JS에서 == 사용시, 형 변환이 일어남에 유의해야한다. 자료형까지 보존하여 비교하고 싶으면 ===을 이용한다.

Why does "1" == 1 return true in Javascript?

스터디시간^^;

스터디시간^^;

//null은 형변환시 0이 된다.
console.log(null>0) //f
console.log(null==0) //f
console.log(null>=0) //t

Mathematically, that’s strange. The last result states that "null is greater than or equal to zero", so in one of the comparisons above it must be true, but they are both false.

The reason is that an equality check == and comparisons > < >= <= work differently. Comparisons convert null to a number, treating it as 0. That’s why (3) null >= 0 is true and (1) null > 0 is false.

On the other hand, the equality check == for undefined and null is defined such that, without any conversions, they equal each other and don’t equal anything else. That’s why (2) null == 0 is false.