Home / Programming MCQs / JavaScript MCQs / Question

D

Durgesh • 8.64K Points
Tutor III

Q. Which of the following is the correct output for the following JavaScript code:

Code:
varx=5,y=1  
var obj ={ x:10}  
with(obj)  
{  
      alert(y)  
}  
(A) 1
(B) Error
(C) 10
(D) 5
Explanation by: Lalit Singh
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.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.