in Web Technologies recategorized
3,009 views
1 vote
1 vote

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, $\dots$, $D_M$ represents the content displayed in the each of the $M$ dialog boxes, then: 

  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=3; D1 displays”12”; D2 displays “6”
in Web Technologies recategorized
3.0k views

1 comment

In D. option value of M=2 in the question paper.
0
0

1 Answer

0 votes
0 votes
Answer must be 4

2 Comments

Alert box will be called 2 times so  m=2

first dialog box alert(this.y) is used to access the value of variable which is outside from f().so d1=12

second dialog box alert(y) inside nested function g() is used to access the local variable y. so d2 will be 6
1
1
What is topic is this??

is it in the gate syllabus??
0
0

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true