Shorthands

suggest change

We can use ~ as a shorthand in some everyday scenarios.

We know that ~ converts -1 to 0, so we can use it with indexOf on array.

indexOf

let items = ['foo', 'bar', 'baz'];
let el = 'a';
if (items.indexOf('a') !== -1) {}

or

if (items.indexOf('a') >= 0) {}

can be re-written as

if (~items.indexOf('a')) {}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents