DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in

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

Collapse
 
pierreatwork profile image
Pierre

Great article !

Do you know if there is any performance gain using this or is it the same as if/else ?

Thanks !

Collapse
 
alainvanhout profile image
Alain Van Hout

I have no idea about execution performance, but I know that excessive use of the ternary operator can very efficiently give you a headache πŸ˜†.

Collapse
 
gaelgthomas profile image
GaΓ«l Thomas Author

Hahaha, you got it! πŸ˜†

Collapse
 
gaelgthomas profile image
GaΓ«l Thomas Author

Thank you, Pierre!

I didn't test by myself, but after reading a few posts talking of that, there isn't much of a difference in performance one way or the other.

The main difference is the way to write a condition and readability.