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"

 

 

 

+ Recent posts