What is "!functionname()"?
This question already has an answer here:
!
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