Home > Back-end >  Javascript Library Execute Without Called
Javascript Library Execute Without Called

Time:11-25

I always see

  (function (e){
     console.log("hi")
  })

in libraries Like jQuery but when I try and make something like it in NodeJS it doesn't Log "hi" to the console. What does it mean?

I've tried searching for multiple different solutions online to see what it meant but I couldn't find anything. So, I came to see if anybody knew what it means.

CodePudding user response:

That's an IIFE mising the second I — an Immediately Invoked Function Expression, but it needs to actually be invoked:

(function (e) {
  console.log("hi")
})() // add parens here

CodePudding user response:

Self call functions are written like:

(function(...) {

})(); // () needed at the end with a semi column

in your case you are missing the ending.

Note: in some cases you need to put a semi column at the beginning of the self invoke function more explanation here

  • Related