🚧 under construction -> example
JS ⟩ statement ⟩ expression ⟩ operator ⟩ logical ⟩
a && b :returns a if a is falsy, otherwise returns b.
a && b
a
b
a || b:returns a if a is truthy, otherwise returns b.
a || b
a ?? b:returns a if a is non-nullish, otherwise returns b.
a ?? b
!a:returns false if a is truthy, otherwise returns true.
!a
false
true
🌟 table of operators
&& and || can do short-circuiting.
&&
||
unlike && and ||, ! always returns true or false.
!
convert any value to Boolean.
!!x // conversion: any -> true/false
falsy / nullish
conditional operator (?:)
optional chaining (?., ?.[])
nullish coalescing (??)
replit:
// Some code
JavaScript: The Definitive Guide ⟩ 4.10 Logical Expressions
Last updated 3 years ago