Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Circe Vixenia
3,270 PointsActually, you could use anonymous functions to replace the named functions and render the correct results.
const clockSection = document.getElementById("clock");
function getTime() {
function pad(number) {
if (number < 10) {
return "0" + number;
} else {
return number;
}
}
const now = new Date();
const hh = pad(now.getHours());
const mm = pad(now.getMinutes());
const ss = pad(now.getSeconds());
return `${hh}:${mm}:${ss}`;
}
function tickClock() {
clockSection.textContent = getTime();
}
() => clockSection.textContent = getTime()
setInterval(() => clockSection.textContent = getTime(), 0);
setInterval(() => clockSection.textContent = getTime(), 1000);
1 Answer
Steven Parker
243,658 PointsTrue, but remember creating the same anonymous function more than once takes up the additional memory for each instance, but references to one named function share the same memory.
One good criteria for choosing an anonymous function for a callback is when you are sure it will not be used anywhere else.