DEV Community

loading...

Conditional (ternary) operator in JavaScript

afewminutesofcode profile image Aaron ・1 min read

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!

Discussion (0)

pic
Editor guide