原因是什么?运算符还是使用字符串? [英] What is the cause? operators or use of strings?

查看:47
本文介绍了原因是什么?运算符还是使用字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么JavaScript中的字符串会发生这种情况?

Why does this happen with strings in javascript?

3<=255
true

但是

'3'<='255'
false

与运算符或字符串的使用有关吗?

Is it something to do with the operators or the use of strings?

推荐答案

我想这是因为它比较char的ascii值,而3的ascii值大于2.在字符串中,如果1 char为false,则逐字符比较char.不会比较

I guess it is because it compare ascii values of chars and 3 had greater ascii value than 2. In string it compare char by char if 1 char is false it wont compare else

这篇关于原因是什么?运算符还是使用字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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