Unable to run anonymous functon

The anonymous function in Functions as Parameters cannot be run when I try to execute it. The error is ReferenceError: timeFuncRuntime is not defined.

timeFuncRuntime(() => {
    for (let i = 10; i>0; i--){
        console.log(i);
    }
});

I see nothing wrong with that

It can be run if you execute it. You’re not executing it, therefore it does not run. Did you read the error message? It’s telling you something about what the problem is.


runs fine:

(() => {
    for (let i = 10; i>0; i--){
        console.log(i);
    }
})()
// 10 9 8 7 6 5 4 3 2 1
4 Likes

ah, running it without the timeFuncRuntime word works. That was confusing me… thanks a lot !

1 Like

Sure, though, the purpose of timeFuncRuntime is to call your function and measure how long it took. If you look at your error message, it says that name wasn’t defined, maybe you removed that code, that was the problem.

1 Like