it seems this only work on "even" numbers:
"8"|0 + 1 // 9
"3"|0 + 1 // 3
("3"|0) + 1 // 4
but "3"|0
translates to the Integer 3
.
so what's going on here?
why does the second example acts like this in JS?
The precedence of + is higher than |.
So it's parsing like this:
"8" | (0 + 1) = "8" | 1 = 9
"3" | (0 + 1) = "3" | 1 = 3
+
has higher precedence than |
so you need to put the brackets in to get the order of evaluation that you want.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.