Does JScript provide a triple operator?

Do I have a ternary operator in Jscript (as opposed to JavaScript)? If so, what is the syntax?

+3
source share
4 answers

it

expression ? expression : expression

like C. This is actually a bit weaker because JavaScript is not very typed. Thus, two possible operator “forks” can lead to different types of values.

In this way:

alert(document.all ? "Hello from IE!" : "Hello from a non-IE browser!");

In most cases, the differences between Microsoft ECMAScript and other browsers (or other server environments) are actually not that big, and for regular code other than the DOM, you rarely have to deal with such things.

+5
source

yes it does.

test ? expression1 : expression2
+2
source

:

var result = 5 > 10 ? '5 is greater than 10' : '5 is not greater than 10';
+1

Google .

The first result I got is http://msdn.microsoft.com/en-us/library/be21c7hw%28v=vs.85%29.aspx . He has examples like

var greeting = "Good" + ((now.getHours() > 17) ? " evening." : " day.");
0
source

All Articles