Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does !(function()) mean in JavaScript/jQuery? [duplicate]

I saw in the ParsleyJs library the folowing:

enter image description here

What does the expression !(function(f){...}) mean?
Is it a negation?

EDIT:
After some explanations, I observed that actually the code looks like

!( f(y){}( f(x){} ) );

or can be written as

!( f(z) );

or

!(Z);

where Z = f(z), z = f(y){}, and finally y = f(x){}...
So is not really clear what function executes the expression !(Z);

like image 964
serhio Avatar asked Oct 31 '25 20:10

serhio


2 Answers

It is a short-hand or alternative for self-invoking anonymous function.

(function(){
//code
})();`

can be written as

!function(){
// code
}();

you can also use + instead of !.

like image 117
Amandeep Singh Avatar answered Nov 02 '25 09:11

Amandeep Singh


Usually you use either

!function(f){...}()

or

(function(f){...})()

or

+function(f){...}()

The developers here combined the first two, which is redundant.

like image 21
meskobalazs Avatar answered Nov 02 '25 11:11

meskobalazs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!