javascript - 运算符 < 不能应用于 Number 和 boolean 类型
问题描述
我有三个数字,我正在尝试比较其中一个是否包含在其他 2 中。
let myMonthly = this.profile.expectedpayhourlystart +
this.profile.expectedpayhourlyend;
myMonthly = ((((myMonthly/2)*8)*5)*4);
let jobStart = item.monthlyPrice - 200;
let jobEnd = item.monthlyPrice + 200;
if( jobEnd < myMonthly < jobStart ){ <-- 'Operator < cannot be applied to boolean or number'
}
为什么我收到此错误?我应该改变什么?
解决方案
jobEnd < myMonthly
将评估为真或假。所以如果你写:
if( jobEnd < myMonthly < jobStart)
它基本上试图评估
if( true < jobStart )
将< 运算符应用于布尔值,因为 jobStart 是一个数字。
你需要这样写:
if( jobEnd < myMonthly && myMonthly < jobStart )
推荐阅读
- node.js - 如何从先前的意图访问参数
- android - Android Studio 4.2 beta 2 中的错误(Android Stuido 模板不工作)
- android - Android 视图绑定 - 多模块项目中未解决的引用
- flutter - 颤振小部件放置在屏幕底部
- java - JNI 将 jbytearay 转换为 std::string
- python - 运行相同 docker 命令的两台主机之间的差异
- typescript - 如何在 RxJS 6 管道运算符中保留一个值?
- swift - 通过 UIButton 使用自定义 TableViewCell 添加到收藏夹并保存到 UserDefaults
- window-functions - 如何为 Presto 编写自定义窗口函数?
- python-3.x - 在 tensorflow 2.4 中使用 sampled_softmax 时,无法将符号 Keras 输入/输出转换为 numpy 数组 TypeError