使用逻辑OR运算符在if语句中进行多次比较 [英] Multiple comparisons in an if statement using the logical OR operator
本文介绍了使用逻辑OR运算符在if语句中进行多次比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想跟随他,但它不起作用:
I want to do he following, but it does not work:
if(pathname == '/ik/services/' || '/ik/recruitment/'){
//run function
}
它完全忽略我的if语句并执行所有页面的代码...
It is completely ignoring my if statement and executes the code for all pages...
推荐答案
你会有做这样的事情:
if(pathname == '/ik/services/' || pathname == '/ik/recruitment/'){
//run function
}
Your || '/ ik / recruitment /'
总是 truthy ,以及if语句中的代码将始终运行。
Your || '/ik/recruitment/'
would always be truthy, and therfor the code within your if-statement will always run.
这篇关于使用逻辑OR运算符在if语句中进行多次比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文