DEV Community

Discussion on: What’s the Ternary Operator in Javascript and How to Use it

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Not at all sure why you mention being able to do 'multiple operations' - using a comma in this way can be done anywhere and does not relate to the ternary operator at all

Collapse
 
gaelgthomas profile image
Gaël Thomas

Hello Jon,

Yes, for sure, you can do it anywhere!
In this article, I'm sharing how to use it with a ternary operation, what you can do with it.

I wanted to show, mainly for newcomers in JavaScript, that you can do multiple operations using this method.

condition ? console.log("Yes") : console.log("No")
Enter fullscreen mode Exit fullscreen mode

I can imagine some people are trying like below, for example, but it's not working.

condition ? console.log("Yes"); console.log("Yes2")  : console.log("No")
Enter fullscreen mode Exit fullscreen mode

It was more like additional information.
I hope it answered your question! 😊