B.array = dic[@"products"];
[cartItems removeAllObjects];
NSLog(@"%@", B.array); ///< B.array won't be empty
我在数字和字符串之间应用左移,结果为10000,如何在JavaScript中解释?
10000<<"5daz"
答案 0 :(得分:0)
Javascript通常会尝试解析其运算符的参数类型,以便它们“有意义”。在这种情况下,它会向String
投射Uint32
,以便它可以执行左移。将String
投射到Uint32
时,会先将其投射到Number
。 If the number is NaN
, then the UInt32 is 0 by the specification.
10000<<"5daz"
与10000<<0
相同,10000
更多阅读,here in the specification。
在其他操作中,NaN
的处理方式不同,这可能会让您对<<
运算符感到惊讶。例如,addition将参数视为Number
s,而不是Uint32
。出于这个原因10000 + "5daz" = NaN
而10000 << "5daz" = 10000