0 votes
in JavaScript by
Which of the following is the correct output for the following JavaScript code:

varx=5,y=1  

var obj ={ x:10}  

with(obj)  

{  

      alert(y)  

}  

a) 1

b) Error

c) 10

d) 5

1 Answer

0 votes
by

Answer: A

Reason: The output of the above snippet code will be one because, first of all, the interpreter will search "obj" for the property (y). But it fails to find "obj" for property "y," so it chooses a value from outside the object, which is available within the given code.

Related questions

0 votes
asked Mar 20, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
...