js ?? ||차이

qwe8851·2025년 8월 26일
0

📚 JavaScript

목록 보기
65/65

|| (OR 연산자) 와 차이점

|| 는 falsy 값(false, 0, '', null, undefined, NaN)을 전부 걸러냄

?? 는 null/undefined만 걸러냄

console.log(0 || 10) // 10 ← 0도 falsy라 기본값 나옴
console.log(0 ?? 10) // 0 ← null/undefined가 아니라서 0 그대로

profile
FrontEnd Developer with Vue.js, TypeScript

0개의 댓글