为什么未定义小于1? [英] Why isn't undefined less than 1?

查看:111
本文介绍了为什么未定义小于1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以在大多数情况下,我已经能够使用类似于这些线条的东西了,但是Javascript给了我这个奇怪的结果。

So in most cases I've been able to use something similar to these lines, but Javascript has given me this weird result.

如果我拿了一些值,结果是未定义,与整数相比,它似乎不小于或大于任何数字。这是为什么?

If I take some value and it turns out to be undefined, when compared to an integer, it does not appear to be less than or greater than any number. Why is this?

if(undefined < 1 || undefined >= 1)
    alert("yes");
else
    alert("no");

//this always alerts no

JSFiddle

推荐答案

没有 operator'<'不能应用于在JavaScript中输入'undefined'错误,就像在其他类型语言中找到的那样。因此,JavaScript使用 false 的运算符评估不兼容类型。

There is no operator '<' can not be applied to type 'undefined' error in JavaScript as you would find in other typed languages. As such, JavaScript evaluates incompatible types with an operator to false.

这篇关于为什么未定义小于1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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