Skip to main content

Command Palette

Search for a command to run...

Ternary Operators

Published
•1 min read•View as Markdown
Ternary Operators

We as developers are not much aware about these operators but when one make project for production i.e companies we use these to increase the readability of the code the majority of the developers use them because :

1) The Ternary operators allows you to write if-else block in more efficient and simple way .

2) The Ternary operators is widely used in many libraries and frameworks which we will discuss further.

IF-ELSE :

if(condition){

print(....)

}else{

print(....)

}

but this becomes very simple using ternary operators

condition ? <expression true> : <expression false> so this is how it makes code look beautiful and more easily readable

Let's look at some examples :

const age = 26; const beverage = age >= 21 ? "Beer" : "Juice"; console.log(beverage);

// "Beer"

C Ternary Operator (With Examples)

i hope the above table would conclude all your doubts then please comment and do comment the next topic you can follow me too at intstagram and linkedin

THANK YOU FOR READING...

HAPPY READING YOU ALL !!!

More from this blog

Intorduction to Front End

9 posts