Hacker News new | ask | show | jobs
by bluesnowmonkey 4053 days ago
Another way to cast to a Number is the bitwise-or operator. It has the useful property of always yielding a number.

    '42' | 0;      // 42
    NaN | 0;       // 0
    null | 0;      // 0
    undefined | 0; // 0
    false | 0;     // 0
    true | 0;      // 1
2 comments

Bitwise operations don't produce Numbers (f64), but signed integers (i32).
> produce...signed integers

Well, except for right logical shifts.

It always yields an integer, so it's useful if you know you want an integer.