DEV Community

Aaron
Aaron

Posted on

2 2

Conditional (ternary) operator in JavaScript

This video shows how you can refactor your existing function using an if statement to a ternary operator.

In our example we create a function that returns true or false based on whether the number has at least 2 digits in it. Initially we do this using an if statement and at the end of the video we show the power of a ternary operator by doing it in a single line.

Have a great weekend!

Top comments (0)

Image of PulumiUP 2025

Let's talk about the current state of cloud and IaC, platform engineering, and security.

Dive into the stories and experiences of innovators and experts, from Startup Founders to Industry Leaders at PulumiUP 2025.

Register Now

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay