Consider the JavaScript Code :

var y= ’’12”;

function f( ) {

var y=’’6”;

alert (this.y);

function g( ) {alert (y); }

g( );

}

f( );

If M is the number of alert dialog boxes generated by this JavaScript code and D1, D2, ....,

DM represents the content displayed in each of the M dialog boxes, then :

This question was previously asked in
UGC NET Computer Science (Paper 2) July 2018 Paper
View all UGC NET Papers >
  1. M = 3; D1 displays ”12”; D2 displays ”6”; D3 displays ”12”.
  2. M = 3; D1 displays ”6”; D2 displays ”12”; D3 displays ”6”.
  3. M = 2; D1 displays ”6”; D2 displays ”12”.
  4. M = 2; D1 displays ”12”; D2 displays ”6”.

Answer (Detailed Solution Below)

Option 4 : M = 2; D1 displays ”12”; D2 displays ”6”.
Free
UGC NET Paper 1: Held on 21st August 2024 Shift 1
13 K Users
50 Questions 100 Marks 60 Mins

Detailed Solution

Download Solution PDF

Concept:

In Javascript, this keyword holds the reference to an object. It may be different each time the function is called. In global execution context (outside of a function), “this” refers to the global object whether in strict mode or not. Inside a function, value of “this” keyword depends on how function is called.

Explanation:

Given code :

var y= ’’12”;

function f( ) {

var y=’’6”;

alert (this.y);

function g( ) {alert (y); }

g( );

}

f( );

In this Javascript code, alert box appear two times. So value of m becomes .

First alert box will show the value of y as 12, as it takes the global value which is outside from the function. So, d1 becomes 12.

Second alert box show the value of y as 6. It takes the local value which is inside the function. So, d2 becomes 6.

Latest UGC NET Updates

Last updated on Jun 19, 2025

-> The UGC NET City Slip 2025 has been released on its official website today.

-> The UGC NET June 2025 exam will be conducted from 25th to 29th June 2025.

-> The UGC-NET exam takes place for 85 subjects, to determine the eligibility for 'Junior Research Fellowship’ and ‘Assistant Professor’ posts, as well as for PhD. admissions.

-> The exam is conducted bi-annually - in June and December cycles.

-> The exam comprises two papers - Paper I and Paper II. Paper I consists of 50 questions and Paper II consists of 100 questions. 

-> The candidates who are preparing for the exam can check the UGC NET Previous Year Papers and UGC NET Test Series to boost their preparations.

Get Free Access Now
Hot Links: teen patti real teen patti all app teen patti real money app teen patti wealth teen patti rummy