JS Coding Questions Logo
JS Coding Questions
#174💼 Interview💻 Code

What is a conditional operator in javascript

Advertisement

728x90

The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.

javascript
1var isAuthenticated = false;
2
3console.log(
4  isAuthenticated ? "Hello, welcome" : "Sorry, you are not authenticated"
5); // Sorry, you are not authenticated

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 3

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
174of476