JavaScript Scope Anonymous invocation

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Invoking a function as an anonymous function, this will be the global object (self in the browser).

function func() {
    return this;
}

func() === window; // true
5

In ECMAScript 5's strict mode, this will be undefined if the function is invoked anonymously.

(function () {
    "use strict";
    func();
}())

This will output

undefined



Got any JavaScript Question?