본문으로 바로가기
728x90
  • Logical - || (falsy)
    falsy 일 때만 오른쪽 값을 채택
  • nullish coalescing operator - ?? (undefined/null)
    null/undefined 일 때만 오른쪽을 채택

> 0 || 1 
1

> 0 ?? 1
0

> null || 1
1

> null ?? 1
1

> "" || 1
1

> "" ?? 1
''

> undefined || 1
1

> undefined ?? 1
1

> NaN || 1
1

> NaN ?? 1
NaN

 

https://medium.com/nerd-for-tech/the-difference-between-and-operators-in-javascript-nodejs-3696b0ce02ff

 

The difference between || and ?? operators in Javascript & NodeJS

In short, the difference between the two operators boils down to the difference between falsyand null/undefined. Where the logical or (||…

medium.com

https://ko.javascript.info/nullish-coalescing-operator

 

nullish 병합 연산자 '??'

 

ko.javascript.info