r/programminghelp • u/TitleTemporary • May 03 '21
JavaScript How to pull a variable from a setInterval (Javascript)
setInterval(()=>{
var timma=d.getHours();
}, 1000);
console.log(timma);
4
Upvotes
r/programminghelp • u/TitleTemporary • May 03 '21
setInterval(()=>{
var timma=d.getHours();
}, 1000);
console.log(timma);
1
u/[deleted] May 03 '21
Timma only exists inside of the set variable inline function. It doesn't exist outside so there's nothing to log. Just create it outside and reference it inside.