ITP

BSc IT - Web Designing

Use of this keyword in JavaScript ?

In : BSc IT Subject : Web Designing

The this keyword in JavaScript is a special reference that refers to the context in which a function is executed — or more simply, it tells you what object the function belongs to when it runs .

1. In Global Scope  
 console.log(this); // In browser: refers to `window` object
 
 Outside of any function or object, this points to the global object (window in browsers, global in Node.js).
     
2. In a Function (Simple Call)  
function showThis() {
  console.log(this);
}
showThis(); // Still refers to the global object (`window`)
    In non-strict mode, this still refers to the global object.
    In strict mode  ("use strict";), this will be undefined.

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap