字符串的余数/模数是一个数字 [英] Remainder/Modulus of string is a number

查看:36
本文介绍了字符串的余数/模数是一个数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这可能?

console.log('13' % 2);

1

我假设 JavaScript 只是自己转换字符串.如果您提供有关此行为的任何信息,我将不胜感激.

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

推荐答案

作为起点:http://ecma-international.org/ecma-262/5.1/#sec-11.5

ToNumber 操作在左参数上执行(这导致左参数被视为数字,如 http://ecma-international.org/ecma-262/5.1/#sec-9.3.1)

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)

这篇关于字符串的余数/模数是一个数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆