+ 2

what's the output?

alert(false?true:false); I don't see why the output would be "false"?

17th May 2020, 6:28 PM
Kajal Kumari
Kajal Kumari - avatar
5 Antworten
+ 5
ternary operator means this: condition ? true : false if condition is true, then choose the option after the ? symbol. if condition is false, then choose the option after the : symbol condition is false, so it will choose the value after the : symbol which is "false"
17th May 2020, 6:56 PM
Sebastian Pacurar
Sebastian Pacurar - avatar
+ 6
U might wanna look up javascript conditional ternary operator to understand what's going on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
17th May 2020, 6:52 PM
Bhavya
Bhavya - avatar
+ 4
If false then true else false Since false is not true you get false
17th May 2020, 6:32 PM
Oma Falk
Oma Falk - avatar
+ 1
The output is false because the expression false? equals false. If it was true?, you would get true.
17th May 2020, 6:32 PM
Sajid
Sajid - avatar
0
The syntax is Condition given ? True : false It's similar to if else - here option just after ? Gets printed if the condition is true and similarly the option just after : gets printed if the condition is false.
19th May 2020, 8:27 AM
Shipra
Shipra - avatar