You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
parseInt 经常被带着一个参数使用, 但是这里接受两个。第一个参数是一个表达式而第二个是 callback function 的基, Array.prototype.map 传递3个参数:
the element the index the array
第三个参数被parseInt忽视了, but not the second one, 但不是第二个。因此可能出现混淆。下面是迭代步骤的简明示例:
// parseInt(string, radix) -> map(parseInt(value, index))/* first iteration (index is 0): */parseInt("1",0);// 1/* second iteration (index is 1): */parseInt("2",1);// NaN/* third iteration (index is 2): */parseInt("3",2);// NaN
不明白的点:parseInt('1', 0),为什么会传进来0。
MDN上这么写的:
它写的让总是显示地显示radix。所以map的index就传进来了,因为parseInt需要两个参数
针对我 不明白的点:对于每个迭代
map
,parseInt()
传递两个参数: 字符串和基数。实际上可以理解成:
所以才是:
The text was updated successfully, but these errors were encountered: