Ever wondered how the null coalescing operator || works in JavaScript?
For those who are wondering what exactly the null coalescing operator is, consider the following example:
1
2
3
var a = null;
var b = a || 10;
console.log(b); // It will log 10
It is very probably that you already used such code in your programs. In the previous example, with the || operator we are practically set the number 10 to variable b, if the value inside variable a is null.
Read the complete article