음악, 삶, 개발
나누기 연산시 조심해야할 녀석들 : Infinity , -Infinity, NaN 본문
< 참고 강좌 : youtu.be/OCCpGh4ujb8?t=906 >
JS 에서 이것저것 계산을 하다보면 나누기를 당연히 자주 하게되는데,
이때 0 으로 나눌 경우 Infinity , -Infinity, NaN 등이 출력된다.
따라서 내가 나눌려는 녀석이 0 인지 아닌지를 확인하는게 중요하다.
const a = 1 / 0
const b = -1 / 0
const c = 'not a number' / 2
console.log(a) // Infinity
console.log(b) // -Infinity
console.log(c) // NaN