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'
?
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'
?
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'