Render React Components conditionally with short circuits

Share this video with your friends

Send Tweet

In this lesson you will learn yet another way of using short circuit operator in JavaScript on the basis of React conditional rendering example

Max Vyz
Max Vyz
~ 5 years ago

Hey, useful tip, but it's also good to mention that not all falsy values are working that way in this "short circuit" notation.

For example if you have some value of type number and you use that notation to decide whether to render the element or not, you might see 0 being rendered when the condition is falsy

Dimitri Ivashchuk
Dimitri Ivashchuk(instructor)
~ 5 years ago

Totally valid point! Forgot to mention this caveat, thanks for pointing out👍🏼 Nullish coalescence operator will be even easier and more predictable to use when it hits support for all of the browsers.