Grokking Advanced JavaScript
Vote

0% completed

​

Miscellaneous Operators

Suppose a user sets the volume of a media player to 0, and the program fills in a default of 50 when no volume is set. Two operators that look alike give different answers here:

const volume = 0; console.log(volume || 50); console.log(volume ?? 50);
50 0

The first line ignores the user's choice, and the second keeps it. The two operators replace different sets of left operands, and 0 is in only one of those sets

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content