Every use of operators can be considered a syntax trick until it becomes common, which is what the author hopes will happen to ~~
Every use of operators can be considered a syntax trick until it becomes common, which is what the author hopes will happen to ~~
That's blatantly false for strict languages, like JavaScript. For a function, all arguments are evaluated before the function is evaluated. For operators this is not true. On the and-case, the second argument is only evaluated if the first one evaluates to something true-ish.
You can only use this supposed and()-function, if you pass closures instead of values and not every language has those.
While at it we should also remove curly braces and go with Basic's if/end if, function/end function and so on.
You could maybe compare `~~` to something like `if (!someString)` but, again, that's a widely used and way more easily understood pattern.
Further you're using a side effect of ~ to get rounding. It isn't being used for its intended purpose.
I get your point and to some extent agree with it.
It's more in the class of
While(foo++ = bar++)
You can do it, but you're to some extent abusing constructs.
If it becomes widely used then it's acceptable, but if not it deemed as bad code. Or clever, depending on your world view.
Also, there are multiple ways to convert to int (~~ is equivalent to truncate). Why leave it ambiguous instead of using Math.trunc / Math.floor / Math.ceil?
$ perl -E 'say 1,2,3,4 and 5; say 1,2,3,4 && 5'
1234
1235