Var p hello var q hello function foo var p goodbye q go

Var p = \"hello\"; var q = \"hello\"; function foo () {var p = \"goodbye\"; q = \"goodbye\";} foo (); var z = p + \" \" + q; After this code executes, what value does z have? Select one: \"goodbye hello\" \"goodbye goodbye\" Undefined \"hello goodbye\" \"hello hello\"

Solution

d. \"hello goodbye\" is the correct answer.

Here, in the function, only p is the local variable, whereas, q is modifying the global variable. Therefore, p will be unmodified outside the function, whereas, q will be modified.

 Var p = \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site