1. Nullish Operator
- The Nullish Coalescing Operator
-
function myFn(variable1, variable2) { let var2 = variable2 ?? "default value" return variable1 + var2 } myFn("this has", " no default value") //returns "this has no default value" myFn("this has no") //returns "this has no default value" myFn("this has no", 0) //returns "this has no 0"
-
- Logical Nullish Operator
-
function myFn(variable1, variable2) { variable2 ??= "default value" return variable1 + variable2 } myFn("this has", " no default value") //returns "this has no default value" myFn("this has no") //returns "this has no default value" myFn("this has no", 0) //returns "this has no 0"
-
'TIL(Today I Learned) > 2022년' 카테고리의 다른 글
01.19 - Custom Hook 사용 조건 / React: Too many re-renders Error (0) | 2022.01.19 |
---|---|
01.14 - return type 'Element[]' is not a valid jsx element (0) | 2022.01.14 |
01.06 TS에서 enum 대신 const를 활용한 union type을 쓰자 (0) | 2022.01.06 |
01.06 open graph meta tag는 www로 시작하는 도메인이 아니면 안먹힘 (0) | 2022.01.06 |
01.05 - 모든 사람에게 좋은 사람은 나쁜 사람? / 직장에서의 페르소나 (0) | 2022.01.05 |