|| 와 ?? 차이
A || B
- falsy()인 값에 대해 default 대체하는 연산자.
""
,null
,undefined
,NaN
,false
,0
A ? B
null
또는undefined
에 대해서만 default값으로 대체하는 연산자.
let x = foo ?? bar(); // 아래와 같은 맥락으로 쓰인다.
let x = foo !== null && foo !== undefined ? foo : bar();
'Language > Typescript' 카테고리의 다른 글
[Typescript] Generics으로 Axios 깔끔하게 사용해보기 (0) | 2024.01.04 |
---|---|
[Typescript] styled Components Typescript Definitions (0) | 2023.01.07 |
[Typescript] Typescript Tutorial (0) | 2023.01.03 |