As shown in the figure, the execution result in REPL mode of node.js is as follows:
I feel this can be replaced.
parseInt, can be avoided
First, let’s look at the description of the bitwise operators:
Note the part I selected, “operands are converted to 32-bit integers,” which is the key to your question.
As for whether it can be completely replaced
parseInt, the individual from the function should be replaceable (may be thoughtless, looking forward to great god advice); However, from the perspective of software engineering, I do not recommend writing it this way. In addition to flaunting one’s skills, in each
On how non-numeric types are silently converted into integer parts, the following
ECMAScriptSome things were said:
I can’t guarantee that the information I found this time will be accurate, but it is very close.
When converting a string into an integer, follow the principle of the above figure. When the first step is used
ToNumberAfter the principle conversion, the actual result is
NaNPay attention to the part I have chosen, and the second step will be to
zeroHere we go. My understanding is that this is why
'abc' | 0 === 0Why?
The document is here:spec