+ 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.
2 Respuestas
+ 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.
0
it's the one from JavaScript Challenge. Thank you anyway for this hint.