+ 1

Meaning of syntax in JavaScript

What is the meaning of this syntax "x?x&&y?y", i tried to figure it out but didn't have any clues. Thanks in advance.

21st Feb 2018, 3:52 PM
Paul Brugman
Paul Brugman - avatar
2 ответов
+ 5
Where are you seeing that at? '?' is the ternary operator in Javascript (as well as most languages). Basically, it allows you to shorten your IF/ELSE statement into one simple expression. EXAMPLE: var result = 5 < 10 ? "True" : "False"; ^As you can see, it's simplified what we would have done with an IF statement. The syntax is as follows: (condition) ? (expression if true) : (expression if false) && - That simply means AND. It is used for multiple conditions which require both conditions to be true. EXAMPLE: IF (2 > 1 && 5 < 10) { } Hopefully this helps explain it to you.
21st Feb 2018, 4:01 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
it's the one from JavaScript Challenge. Thank you anyway for this hint.
21st Feb 2018, 4:21 PM
Paul Brugman
Paul Brugman - avatar