Mansi Manhas
Mar 28, 2023

--

Great article and explanation! ๐Ÿ‘

However, It would also be good to know about the difference between ?? and ||.

Explanation:

The OR operator uses the right value if the left is "falsy", whereas nullish coalesce uses the right value if the left is "null" or "undefined"

So, the OR operator might be problematic if the left value contains an empty string (" ") or zero number. In those cases, it would be useful to use "??".

Example:

0 || "not found" ===> "not found"

0 ?? "not found" ===> "0"

--

--

Mansi Manhas
Mansi Manhas

Written by Mansi Manhas

Here, I share in-depth tutorials and industry insights to help you master web development. Let's learn and grow together. Happy reading!

No responses yet