It’s binary inversion. ~n = -(n + 1)
For further actions, you may consider blocking this person and/or reporting abuse
For further actions, you may consider blocking this person and/or reporting abuse
Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.
👥 Ideal for solo developers, teams, and cross-company projects
Velan<> -
MD ARIFUL HAQUE -
Gabor Szabo -
Ahmed Rakan -
Top comments (1)
There is a nice trick of turning
indexOf
results into booleans involving this method.Take the following code:
Can be turned into:
Since
-1
will turn to 0 it will be resolved asfalse
when doing a naive bool comparison, and other numbers (0 and up) will change into numbers which will be consideredtrue
.I personally prefer to have things more readable, and also there are standard methods that aim to remove the need for these types of checked (
includes
for example), so I don't use it at all. But it's a nice thing to think about :)