Javascript equality triple equals but what about greater than and less than?

后端 未结 4 2020
轮回少年
轮回少年 2021-02-07 05:11

I was explaining to a colleague that you should use === and !== (and >== and <== of course) when comparing variables in

4条回答
  •  孤独总比滥情好
    2021-02-07 05:52

    I referenced Flanagan's JavaScript: The Definitive Guide (5th Ed.) and there does not seem to be non-coercive comparison operators.

    You are right in saying the << and >> are indeed bitwise operators so that wouldn't work.

    I would suggest you deliberately coerce the values youself:

    var num_as_string = '4';
    var num = +num_as_string;
    if (5 > num) { ... }
    

提交回复
热议问题