what does !function in Javascript mean? (ok)

https://stackoverflow.com/questions/9267289/what-does-function-in-javascript-mean

41

It is short-hand or alternative of self-invoking anonymous function:

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

Can be written:

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

You can also use + instead of !.

If you simply did:

function(){
  // code
}();

That will create problems, that's why you need to add ! before it which turns the function declaration into function expression.

Đọc thêm bài này: https://app.gitbook.com/@javascriptuse/s/advanced/javascript-self-invoking-functions-ok

Last updated

Navigation

Lionel

@Copyright 2023