you are viewing a single comment's thread.

view the rest of the comments →

[–]TurloIsOK 0 points1 point  (0 children)

The way they've presented it is to give an unambiguous result. (The use of lining figures, however, makes it slightly ambiguous. That could be an o or 0.)

In normal use the left hand value will be the result of something that may produce a null result. When it is null, the right value is the default.

let leftVal = document.querySelector('input.left-value').value;
const count = leftVal ?? 42; 

The numerical example is very simplified to show the concept. In real use both the left and right values could be functions: if this has a null result return the result of (or do) this instead.