Member-only story
Stop Using Logical OR, Use ?? Instead
You can use logical operators for many things, but just stop using them for everything! We have something better now.
JavaScript has a very flexible syntax; you can use the same syntactical expressions in various ways to accomplish different things; this is one of the benefits of programming in JavaScript.
Software developers (in any language) typically use the || operator when evaluating boolean expressions for truth. JavaScript developers can also use it in other ways.
Software often uses default values — also known as fallback values. If data does not exist, then a fallback value is used instead. Before ES2020, developers accomplished this using the logical OR operator.
Notice how the above code uses the logical OR operator to fall back to 5 if outOf is null or undefined. The above code is a nicer way of writing:








