JS – What does (~) tilde do in this code snippet? [duplicate]

  javascript

I came over this public code snippet on Github. I do not understand what does the ~ do in the if statement. I googled but could not find any asnwer.

if (!~index) return o === undefined ? fallback : o;
for (let i = 0; i < index; i++) {
    if (!isObject(o) || o[props[i]] === undefined) return fallback;
    o = o[props[i]];
}

What does ~ do ?

Source: Ask Javascript Questions

LEAVE A COMMENT