Question:How to use ternary operator in JavaScript? 

Answer The ternary(?) operator can be used as a shortcut for an if....else statement. It is typically used as part of a larger expression where an if...else statement would be awkward. For example:
var now = new Date();
var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");
The example creates a string containing "Good evening." if it is after 6pm. 

+ Report
Total Preview: 1066
How to use ternary operator in JavaScript?
Copyright © 2024. Powered by Intellect Software Ltd