Back to Blog
Javascript questionmark operator6/17/2023 ![]() Here is how the double question mark operator behaves: typescript console.log( null ? "default") // "default" console.log( undefined ? "default") // "default" console.log( false ? "default") // false console.log( "" ? "default") // "" console.log( 0 ? "default") // 0 console.log( 42 ? "default") // 42Īs you can see, the nullish coalescing operator falls back to the default value ONLY when the variable is null or undefined. The double bar operator fallbacks when the value of the left-hand operand is falsy ( null, undefined, 0, '', NaN, false).The double question mark operator fallbacks when the value of the left-hand operand is null or undefined.The difference between the double question mark and the double bar operators is: Since both operators provide default fallbacks, many developers confuse them. ![]() The best Web Development course in 2023! □ Learn Web Development Difference between double question mark VS double bar
0 Comments
Read More
Leave a Reply. |