var i = 0; function a(callback){ i +=1; callback(i); }; setInterval(a((num)=>{ console.log(num); }),1000);
The above is the code I made. I expected that it would come out as 1, 2, 3... every second, but with the error TypeError: "callback" argument must be a function, only 1 is printed and finished.
Why is this happening?
node.js callback
setInterval()
The first factor that the function receives should be a function, but it contains the contents of the function. It works by enclosing a((num)=>{ console.log(num);})
with an anonymous function.
© 2024 OneMinuteCode. All rights reserved.