Ternary operators in Javascript

Owen Abbott
Dec 6, 2020

Say you have to write an if statement.

Typically, it might look something like this:

if (thing === thing2){     console.log(“sentence.”)}

That works, but you also have the option of writing a ternary statement.

Here’s what that looks like:

thing===thing2 ? console.log("sentence.") : null

Pretty neat, huh? Reduced everything to just one line.

That concludes our microlesson for today.

--

--