The this operator in the global context

In the global context, the this operator will always point to the global object. In a web browser, the window object is the global object:

console.log(this === window); // true 
this.a = 37; 
console.log(window.a); // 37 
console.log(window.document === this.document); // true 
console.log(this.document === document); // true 
console.log(window.document === document); // true 
The preceding example is a JavaScript example, not a TypeScript example.

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.