728x90
반응형

Nullish Coalescing Operator (??)

The ?? operator returns the first argument if it is not nullish (null or undefined).

Otherwise it returns the second argument.

ex)let name = null;
let text = "missing";
let result = name ?? text;  // result  ==  "missing"

 

The Optional Chaining Operator (?.)

The ?. operator returns undefined if an object is undefined or null

ex) // Create an object:
const car = {type:"Fiat", model:"500", color:"white"};
// Ask for car name:
document.getElementById("demo").innerHTML = car?.name;

728x90
반응형

'JAVASCRIPT' 카테고리의 다른 글

20241128_1 Type Conversion  (0) 2024.11.28
20241125_1 Loop  (12) 2024.11.25
20241122_2 Math Object  (0) 2024.11.22
20241122_1 Date Objects  (0) 2024.11.22
20241121_2 Arrays  (0) 2024.11.21

+ Recent posts