From the course: Mastering Web Developer Interview Code

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

How does an IIFE work?

How does an IIFE work?

- [Instructor] An IIFE is a convention in JavaScript, that helps you protect variables as well as execute some code immediately. So, good question that you may be asked in an interview is what an IIFE is and you may be asked to explain how it works a little bit. Now, here's what one of these look like and you've probably seen these all over the web. We have like a function declaration and it has no name. So sometimes this is known as an anonymous function and you'll notice that there is an extra set of parentheses around this function, which converts this function to an expression. There's also a separate set of parentheses and these are essentially calling the function expression. So, and if he stands for immediately invoked function expression, and there's a lot of verbiage right there. So let's break it down piece by piece. Now, first off, this is a function that we want to execute immediately. The scripts execute in…

Contents