- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are Conditional Operators in JavaScript?
The conditional operator first evaluates an expression for a true or false value and then executes one of the two given statements depending upon the result of the evaluation.
Sr.No | Operator and Description |
---|---|
1 | ? : (Conditional ) If Condition is true? Then value X: Otherwise value Y |
Example
Try the following code to understand how the Conditional Operator works in JavaScript:
<html> <body> <script> <!-- var a = 10; var b = 20; var linebreak = "<br />"; document.write ("((a > b) ? 100 : 200) => "); result = (a > b) ? 100 : 200; document.write(result); document.write(linebreak); document.write ("((a < b) ? 100 : 200) => "); result = (a < b) ? 100 : 200; document.write(result); document.write(linebreak); //--> </script> <p>Set the variables to different values and different operators and then try...</p> </body> </html>
- Related Articles
- What are operators in JavaScript?
- What are JavaScript Operators
- What are Arithmetic Operators in JavaScript?
- What are Comparison Operators in JavaScript?
- What are Logical Operators in JavaScript?
- What are Assignment Operators in JavaScript?
- What are JavaScript Bitwise Operators?
- What are basic JavaScript mathematical operators?
- What is Conditional Operator (?:) in JavaScript?
- What types of logical operators are in javascript?
- What are conditional attributes in C#?
- What are the latest operators added to JavaScript?
- Conditional statements in JavaScript
- What are assignment operators in C#?
- What are arithmetic operators in C#?

Advertisements