admin管理员组文章数量:1287267
I have three numbers and I am trying to pare if one of them includes in other 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'
}
Why I am getting this error ? What should I change ?
I have three numbers and I am trying to pare if one of them includes in other 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'
}
Why I am getting this error ? What should I change ?
Share Improve this question asked May 8, 2019 at 14:59 DevlaDevla 3565 silver badges20 bronze badges 3-
3
if (jobEnd < myMonthly && myMonthly < jobStart)
– ps2goat Commented May 8, 2019 at 15:02 - Yep this helped. Will wait for the explanation why this works and that didn't. – Devla Commented May 8, 2019 at 15:04
-
1
The
<
operator is binary, has two operands, the problem is that the expression is parsed as:(jobEnd < myMonthly) < jobStart
, the first operand(jobEnd < myMonthly)
results in a boolean value, and the subsequent operator gets a boolean and a number. Check the AST – Christian C. Salvadó Commented May 8, 2019 at 15:07
2 Answers
Reset to default 10jobEnd < myMonthly
will evaluate to true or false. So if you write:
if( jobEnd < myMonthly < jobStart)
it essentially tries to evaluate
if( true < jobStart )
which is applying a < operator to boolean because jobStart is a number.
You need to write it like this:
if( jobEnd < myMonthly && myMonthly < jobStart )
If you stack the < operator like that it will evaluate jobEnd < myMonthly
which results in a boolean and pare the result to jobStart
which is a number. Use &&
like
if (jobEnd < myMonthly && myMonthly < jobStart)
本文标签: javascriptOperator lt cannot be applied to types Number and booleanStack Overflow
版权声明:本文标题:javascript - Operator < cannot be applied to types Number and boolean - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741307610a2371463.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论