Horje
What are Ternary Operator in JavaScript?

The ternary operator in JavaScript is specified using a condition followed by a question mark and semi-colon (condition ? :). It shortens the decision-making process into a single line, consisting of a condition followed by two statements which are separated by a colon. If the condition is true, the expression after the question mark will be executed. Otherwise, the expression after the colon will be executed. This ternary operator enhances the code readability and reduces verbosity in those cases where simple choices are involved. It can be used as an alternative to the if-else statements in JavaScript.

Syntax:

condition expression ? statement1 : statement2;



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
Maximum Frequency Character in String in JavaScript Maximum Frequency Character in String in JavaScript
JavaScript Program to Calculate Power Using Recursion JavaScript Program to Calculate Power Using Recursion
Replace all Occurrences of a Substring in a String in JavaScript Replace all Occurrences of a Substring in a String in JavaScript
How to Declare Variables in TypeScript ? How to Declare Variables in TypeScript ?
Explain the Concept of Interfaces in TypeScript ? Explain the Concept of Interfaces in TypeScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12