r/programminghelp • • May 03 '21

JavaScript How to pull a variable from a setInterval (Javascript)

setInterval(()=>{
var timma=d.getHours();
}, 1000);
console.log(timma);
4 Upvotes

1 comment sorted by

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.