Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the state stored in d in the following JavaScript code?
var c = counter(), d = counter();
c.count()
d.count()
c.reset()
c.count()
d.count()

What will be the state stored in d in the following JavaScript code?
var c = counter(), d = counter();
c.count()
d.count()
c.reset()
c.count()
d.count()
a) 1
b) 0
c) null
d) Undefined

Answer: a
Explanation: Counter function increments the value of the variable by 1 and reset function sets the value of the variable back to 0.as d is incremented twice and reset function is not called on d therefore the value of d is 2.

Join The Discussion