Can we get the Logical And(&&) operator
-
Hey,
can we get the
&&
operator similar to the?
(ternary) operator?Basically
&&
is alogical AND
so:if (data.hover) { Console.print('really not so smoooth'); }
can become just one beautiful single line of code:
data.hover && Console.print('smooooooth');
I believe you can already achieve something like this by using:
data.hover ? Console.print('not so smoooth') : null;
however it lacks class and elegance :)) Its also a javascript basic for years now.
-
@oskarsh already there just put it in parentheses.
doesn't do what you want though, you still need a conditional statement -
-
@ulrik Woah, that's not what I expected
-
@ulrik wait what? Is this new??
-
@ulrik Is this not dangerous? I mean console operations are removed/ignored at compile time so this might end up in a bug unless @Christoph-Hart has put a security... But I don't know...
-
@ustk actually I don't know either, I just tested this yesterday but I will not use it in my code unless I'm sure it's safe.
But it could be tested of course. -
The console operations are not removed but replaced with a noop, so the short-circuit logic still works the same.