What will be the output of the following JavaScript code? [code] var a=5 , b=1 var obj = { a : 10 } with(obj) { alert(b) } [/code]

Thảo Justin

New member
What will be the output of the following JavaScript code?
Code:
var a=5 , b=1
var obj = { a : 10 }
with(obj) 
{
      alert(b)
}
A. 10
B. Error
C. 1
D. 5
 
Answer: c
Explanation: Firstly the interpreter checks obj for property b. But it doesn’t find any property b so it takes the value from outside the object within the code snippet.
 

Tìm kiếm

Back
Top