[removed] How can I simplify an if-statement with multiple OR conditions?

前端 未结 6 960
半阙折子戏
半阙折子戏 2021-01-16 17:22

Sorry if I\'ve made mistakes writing this post. I\'m new here and I don\'t know how this works, hope I learn quick. I am also new at JavaScript.

So the question is:

6条回答
  •  粉色の甜心
    2021-01-16 17:57

    Yes, you have to make it the 'normal' way.

    What

    if (codePrompt == (codeSwitch || codeSwitchBG || codeBlur || codeShowInfo)){};
    

    does is

    1) test all the switches -- returns TRUE if any are TRUE

    2) test if codePrompt == TRUE or FALSE.

    Based on your code, you can remove that test altogether and simply drop through to your final ELSE.

    Another option is use a SWITCH statement, the last ELSE becoming the DEFAULT clause.

提交回复
热议问题