Built a 12-hour digital clock in JavaScript today ⏰
What clicked:
- setInterval waits before its 1st run
- padStart() turns 5 into 05
- % and || convert 24h to 12h
- return ≠ updating the screen
#JavaScript#buildinpublic
Today, I learnt two foundational time-based functions in JavaScript: setTimeout and setInterval.
setTimeout(): Runs a function only once after a specified delay. Perfect for delayed UI popups.setInterval(): Runs a function repeatedly at fixed intervals.