Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

The Global Object

When a function is called without an associated object, the value of this refers to the global object.

In a web browser, the global object is the window object.

This example returns the window object as the value of this:

Example

let x = myFunction();            // x will be the window object

function myFunction() {
  return this;
}

Invoking a function as a global function sets the value of this to the global object.

Using the window object as a variable can easily lead to program crashes.