Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Ternary conditional operator
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===JavaScript=== The conditional operator in [[JavaScript]] is similar to that of [[C++]] and [[Java (programming language)|Java]], except for the fact the middle expression cannot be a comma expression. Also, as in C++, but unlike in [[C (programming language)|C]] or [[Perl]], it will not bind tighter than an assignment to its rightβ{{code|1=q ? a : b = c}} is equivalent to {{code|1=q ? a : (b = c)}} instead of {{code|1=(q ? a : b) = c}}.<ref>{{cite web|title=ECMA-262 Edition 5.1|url=http://www.ecma-international.org/ecma-262/5.1/#sec-11.12|work=Ecma Language Specification|publisher=Ecma International|access-date=7 September 2013}}</ref> <syntaxhighlight lang="javascript"> var timeout = settings === null ? 1000 : settings.timeout; </syntaxhighlight> Just like C# and Java, the expression will only be evaluated if, and only if, the expression is the matching one for the condition given; the other expression will not be evaluated.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)