Nullish Coalescing in JavaScript
Level 2108 keystrokes
Uses ?? operator to provide a default value when the left side is null or undefined.
JavaScript code
// Declare a variable with null (no value)1let value1 = null;// Declare a variable with a string value2let value2 = "Hello";// ?? returns the right side if left is null or undefined// value1 is null, so "default" is returned3console.log(value1 ?? "default");// value2 has a value, so "Hello" is returned4console.log(value2 ?? "default");Output
default Hello
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
"× 6;× 4?× 4.× 2(× 2)× 2=× 2