x|0 is a standard idiom, as explained in the ECMAScript Spec:
The production A : A @ B, where @ is one of the bitwise operators in the productions above, is evaluated as follows:
- Let lref be the result of evaluating A.
- Let lval be GetValue(lref).
- Let rref be the result of evaluating B.
- Let rval be GetValue(rref).
- Let lnum be ToInt32(lval).* <-- Convert to 32 bit Integer
- Let rnum be ToInt32(rval).*
- Return the result of applying the bitwise operator @ to lnum and rnum. The result is a signed 32 bit integer.
x|0 is therefore the result of ToInt32(x), which is effectively a coercion to integer.