Important Notice:

Course Content
Switch Statement
0/1
break and continue Statements
0/3
Basic Form Validation in JavaScript
0/1
JavaScript & Angular JS (Chapter- 6) M2-R5.1
About Lesson

Conditional Operators (Ternary Operator):-

                 जावा में conditional operator को ternary operator भी कहते हैं इस ऑपरेटर में 3 operands होते हैं और इसका प्रयोग Boolean expression को evaluate करने के लिए किया जाता है conditional operator को if-else की तरह ही होता है इसे आप one-line if else statement भी कह सकते है इसे प्रयोग करना बहुत ही आसन होता है question mark से पहले से एक condition दी जाती है यदि आप ये condition को true होता है तो colon के पहले वाला statement और यदि false होती है तो colon के बाद वाला statement को result के रूप में return किया जाता है

Syntax:-   Condition ? expression 1 : expression 2

Example:- z=(5>3) ? 5:3;document.write(z); //it will print 5

Note:-    

Condition:- here we give any  valid JavaScript condition

Expr1:-  it returns this expression if the condition evaluates to true

Expr2:- it returns this expression if the condition evaluates to false

 

 

Conditional Operators (Ternary Operator):-

                     In Java, conditional operator is also called ternary operator. This operator has 3 operands and is used to evaluate Boolean expression. Conditional operator is similar to if-else, you can also write it as one-line if else statement. It can be said that it is very easy to use, a condition is given before the question mark, if this condition is true then the statement before the colon and if it is false then the statement after the colon is given as the result. is returned in

Syntax:-   Condition ? expression 1 : expression 2

Example:- z=(5>3) ? 5:3;document.write(z); //it will print 5

Note:-    

Condition:- here we give any  valid JavaScript condition

Expr1:-  it returns this expression if the condition evaluates to true

Expr2:- it returns this expression if the condition evaluates to false

error: Content is protected !!