TIL(Today I Learned)/2022년
01.11 - Nullish Operator
심리밀당남
2022. 1. 11. 13:07
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"
-