Given the following code var valueA 5 var valueB 6 functio

Given the following code: var valueA = 5; var valueB = 6; function someFunc(a, b) {var valueA = 4; var valueC = 3; valueB = valueA + valueB; valueC = 3; return valueC + valueA;} valueA = someFunc(valueA, 3); What are the values assigned to valueA and valueB after the code executed? Which variables are global? Which variables are local to someFunc?

Solution

a) after executing the code valueA = 4 and valueB=10

4 is initialized to valueA inside the function. and valueB is assigned like ,

valueB=valueA+valueB

valueB is already initialized with 6 in the 2nd line. so 4+6 = 10

b) Global variables to the function is valueA and valueB.

   Local variables to the function is valueA and valueC.

   valueA is again declared inside the function. so it will act as local to that function. the first valueA will act as global variable.

*****************END*****************PLS GIVE ME GOOD RATING***********************************

 Given the following code: var valueA = 5; var valueB = 6; function someFunc(a, b) {var valueA = 4; var valueC = 3; valueB = valueA + valueB; valueC = 3; return

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site