in JavaScript by
In the following code, what value should the variable "a" contain?

var x =counter(), y = counter();  

x.count()  

y.count()  

x.reset()  

x.count()  

y.count()  

a) Null

b) 0

c) 2

d) Undefined

1 Answer

0 votes
by

Answer: C

Reason: The "counter()" method used in the above code made increment in the value of the variable by one each time it is called, and the" reset()" function resets the value of that variable to zero. Therefore if we look carefully, we can see that on variable "y" the "counter()" method was called two times, and the "reset()" method was not called even for one time, so the value of the variable y will be 2.

Related questions

0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 22, 2021 in JavaScript by Robindeniel
0 votes
asked Mar 23, 2021 in JavaScript by sharadyadav1986
...