What is an IIFE (Immediately Invoked Function Expression) in JavaScript?

What is an IIFE (Immediately Invoked Function Expression) in JavaScript?

a) A function that runs as soon as it is defined
b) A function that runs at the end of the script
c) A function that is called multiple times
d) A function that waits for a user event

Answer:

a) A function that runs as soon as it is defined

Explanation:

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs immediately after it is defined. This pattern is often used to create a private scope for variables and prevent them from polluting the global namespace.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top