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
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1
Explanation: 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.
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
573
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Durgesh
Publisher
πŸ“ˆ
90%
Success Rate