Home » JavaScript » JavaScript Statements » Question

JavaScript Statements

  1. What would be the most appropriate output for the following code snippet?
    var p=15 , q=10
    var object = { p : 20 }
    with(object)
    {
    alert(q)
    }
    1. 20
    2. Error
    3. 15
    4. 10
    5. None of these
Correct Option: D

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.



Your comments will be displayed only after manual approval.