首页 > 解决方案 > problem with JS comparison logic if/and/or

问题描述

so here is the scenario

if ( ( a >= b) && ( (c < d) && (d != '') ) )

cannot get this logic on this to work correctly

so if d = '' it would cause that to be false. which would mean that the whole thing would equate to false. Problem is I need it to trigger when a >= b but also needs to include the and for c < d but only if d != '', in other words ignore the c < d part if d = '', otherwise used the c < d part to prevent a >= b from triggering.

hope this is making sense. I am trying to avoid doing and if/else or switch.

标签: javascript

解决方案


感谢您的建议,虽然我只是提出了一个解决方法

if (d == '') { d = Infinity; }

然后

if ( (a >= b) && (c < d) )

这解决了它

感谢大家的帮助


推荐阅读