Remainder/Modulus of string is a number

与世无争的帅哥 提交于 2020-01-04 00:58:03

问题


Why is this even possible?

console.log('13' % 2);

1

I assume JavaScript just converts the string on its own. I would appreciate any info on this behaviour.


回答1:


As a starting point: http://ecma-international.org/ecma-262/5.1/#sec-11.5

The ToNumber operation is performed on the left argument (which results in the left argument being treated as the number, as explained in http://ecma-international.org/ecma-262/5.1/#sec-9.3.1)



来源:https://stackoverflow.com/questions/17140073/remainder-modulus-of-string-is-a-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!