Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - Self Invoking Functions

Function expressions can be made "self-invoking". A self-invoking expression is invoked (started) automatically, without being called. Function expressions will execute automatically if the expression is followed by (). You have to add parentheses around the function to indicate that it is a function expression.

Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. Most loops can be rewritten in a recursive style, and in some functional languages this approach to looping is the default.


// we wrap the function in parentheses to indicate that it a function expression!
(function ()
{
    var x = "Hello!!"; // I will invoke myself
})
(); // Function expressions will execute automatically if the expression is followed by ().
// The function above is actually an anonymous self-invoking function (function without name).