I want to write the following C# code equivalent in JavaScript/jQuery
(x == 0 && y < 0 ? x : x+y)
Is there an equivalent shorthand way such as above in JavaScript/jQuery or will I have to write the whole if else.
I need to put such a condition in the for loop definition,
for (i=0; i< (x == 0 && y < 0 ? x-y : x+y); i++)
and thus was wondering if there is a way I could do something similar in JavaScript. As far as I know, I will have to write an if else, compute the value and then use that value. But perhaps somebody knows a better way?
Yes, the ternary operator also exists in Javascript.
The code you posted
will work, verbatim.