+ 1
setInterval working differently for a function with Global Variable & Local Variable!
While trying to see whether Time changes if variable is outside the function and, Found that the function with local variable doesn’t change Time ! So can anyone explain me why does this happen? https://code.sololearn.com/WEm06Nrl88q0/?ref=app
12 ответов
+ 1
You get time from a var "d"... Now in "printtime" function you init (local) "d" any time that this function its called hence it will contain always up-to-date time...
In "printer" function you dont init "d" (the global one that you have inited on line 15) but use it for get hour, minites and seconds and because your global "d" its setted only one time (on line 15) it will contain always same date hence in "printer" function you will retrieve always same hour, minutes and seconds.... Sorry i cant explain better
+ 1
Your forget that on local one, you init all vars (hour, minute etc) to current time (because your get it at begin of function)... With global one you init d one time only before call it hence you will get same vars (eg. will be printed same time)
+ 1
bro, function kulla variables irukum bodhu, setInterval thirumba thirumba call pannum bodhu, vary aayitey irukum....
but printer function la neenga just already set panna variables ah mattum dha call panreenga, so execute pannum bodhu irundha value mattum andha interval ku thirumba thirumba print aagudhu
+ 1
Hemath Kumar
Thanks nanba ippo purinjiruchu! 😁👌🏻
+ 1
namakula edhuku nanba thanks....!!😘
+ 1
Discord open panniruken.... but epdi use panradhunu onnumey purila bro....😂
+ 1
Hemath Kumar
😂😂
Bro Solo-Learn server la join pannitingala, Pannala na
Intha code la Javascript la Link iruku join pannuga
https://code.sololearn.com/Wu52hMg7JRmF/?ref=app
+ 1
KrOW
No need not explain again coz i understand it now, Thanks man 😊🙌🏻
+ 1
👍👍👍
0
KrOW
I dont get it fully could explain it in a better way please?
0
Hemath Kumar
Bro neenga discord la irukingala?
0
irunga poi paakura