What is "!functionname()"?

This question already has an answer here:

  • What does the exclamation mark do before the function? 9 answers

  • ! is the boolean not operator. !function() converts the return value of function() to boolean and returns its opposite value


    If you are substituting the word "function" for the name of a function, it simply means "negate the result of the function". The ! means not. So

    !true == false
    

    functionname is an expression (which presumably evaluates to a function-object) and the result of this evaluation (a function-object) is invoked with () which invokes the function and evaluates to the return value.

    Now, this return value (which was the result of an expression) is then negated with the unary ! (not) operator. The rules for ! are !truthy -> false and !falsy -> true , where truthy and falsy are concepts covered "truthy and falsy" in JavaScript.

    The example could be written as: !((functioname)()) , but that's just silly

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

    上一篇: 这是什么JavaScript的语法? !功能(){}

    下一篇: 什么是“!functionname()”?