using bitwise OR in javascript to convert to integer
问题 we can do the following to convert: var a = "129.13"|0, // becomes 129 var b = 11.12|0; // becomes 11 var c = "112"|0; // becomes 112 This seem to work but not sure if this is a standard JS feature. Does any one have any idea if this is safe to use for converting strings and decimals to integers ? 回答1: Yes, it is standard behavior. Bitwise operators only operate on integers, so they convert whatever number they're give to signed 32 bit integer. This means that the max range is that of signed