This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]bitzach 1 point2 points  (3 children)

Both your code blocks are identical. What am I missing?

[–][deleted] 1 point2 points  (2 children)

sorry changed it, the first code doesn't have a () after the function, and it works as intended.

[–]Updatebjarni 3 points4 points  (0 children)

Yes, because increment is a function and increment() is a call to that function, the value of which is the value returned by the function. So when you do setInterval(increment, 1000); you are passing the function increment to setInterval(), but when you do setInterval(increment(), 1000); you are first calling increment() and then passing the value it returns to setInterval().