Consider the following code: <script type=”text/javascript”> var v1 = “alpha”; function f () { var v2 =
“bravo”; alert (v1 + “, ” + v2); } f(); v1=”charlie”; alert (v1 + “, ” + v2); </script> What is the expected
result when you run this script in the browser?
A.
An alert box displaying charlie, bravo
B.
An alert box displaying alpha, bravo followed by an error
C.
Two alert boxes displaying alpha, bravo and alpha, bravo respectively
D.
Two alert boxes displaying alpha, bravo and charlie, bravo respectively, followed by an error
Explanation:
Correct – The v2 variable is not global and a call to it outside of the function would result in an error.