Self-Executing Functions

Instead of manually calling a function, you can automatically run it as soon as the page loads using an Immediately Invoked Function Expression (IIFE).

Here’s the syntax:

(function helloWorld() {
alert("Hello World");
// Add your custom functionality here
})();

This pattern is useful for initialization code or running scripts right when the page loads — no need to call the function separately.

Leave a Reply

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