Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  133] [ 4]  / answers: 1 / hits: 48190  / 12 Years ago, thu, october 11, 2012, 12:00:00
alert(test: +(1==2)?'hello':'world');


This should show me 'world' on the screen since 1 is not equal to 2.



How come it alerts 'hello'?


More From » javascript

 Answers
8

Try wrapping your parens around the operation



alert(test: + (1 == 2 ? 'hello' : 'world'));


demo: http://jsfiddle.net/hunter/K3PKx/






what this is doing:



alert(test: +(1==2)?'hello':'world');


is evaluating test: + (1==2) as true which outputs 'hello'


[#82600] Wednesday, October 10, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
myakylas

Total Points: 66
Total Questions: 85
Total Answers: 95

Location: Guadeloupe
Member since Sat, Aug 22, 2020
4 Years ago
myakylas questions
Thu, Apr 28, 22, 00:00, 2 Years ago
Thu, Apr 8, 21, 00:00, 3 Years ago
Sat, Sep 19, 20, 00:00, 4 Years ago
;