What is the Javascript equivalent of writing 'If not"

This question already has an answer here:

  • Best way to find if an item is in a JavaScript array? [duplicate] 8 answers
  • How do I check if an array includes an object in JavaScript? 40 answers

  • The correct syntax is

    if(!condition){
        expression();
    }
    

    Note that you need parenthesis around the condition.


    @plalx wants a formal definition, and here you go:

    IfStatement:
        if(Expression) Statement else Statement
        if(Expression) Statement
    

    In case of any ambiguity the else would be matched with the nearest if .


    If you have some value:

    var excludeMe = "something unwanted";
    

    Then you can use the following if statement:

    if(myTestCase !== excludeMe) { //do something...} 
    

    Keep in mind that != does not check type and !== does check type. So, 1 != "1" is false and 1 !== "1" is true.

    链接地址: http://www.djcxy.com/p/74946.html

    上一篇: 查找数组中的特定对象以删除

    下一篇: 什么是Javascript的等价写作'如果不是'