Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
It’s possible to create an anonymous function statement that is self-invoked. This is called a self-invoking anonymous function. Below, we create several anonymous functions that are immediately invoked.
<!DOCTYPE html><html lang="en"><body><script> // most commonly used/seen in the wild (function(msg) { console.log(msg); })('Hi'); // slightly different but achieving the same thing: (function(msg) { console.log(msg) }('Hi')); // the shortest possible solution !function sayHi(msg) {console.log(msg);}('Hi'); // FYI, this does NOT work! // function sayHi() {console.log('hi');}(); </script></body></html>