What is the expected result when you run this script in the browser?

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?

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:



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Stan

Stan

Correct – The v2 variable is not global and a call to it outside of the function would result in an error.