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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️