Inconsistent function behavior? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 7

Inconsistent function behavior?

Can someone explain this for me? if I call a function within setInterval, it doesn't work. eg. 1.setInterval(player(), 3000); //this won't work. 2.setInterval(player, 3000); //this would rather work however for other functions like console.log, alert etc, if I call it without the '()' it returns the function definition

4th Aug 2020, 3:51 PM
Nyakotey🇬🇭🎹
Nyakotey🇬🇭🎹 - avatar
2 Answers
+ 1
SetInerval is used for function only and it accept function name value as first parameter if it is defined anywhere it will run. But in case alert,console .... it can be used for string ,numbers,fxn .... hence it require () to recognise that parameter is a fxn.
4th Aug 2020, 5:20 PM
Divya Mohan
Divya Mohan - avatar
+ 3
thanks 👍
4th Aug 2020, 6:00 PM
Nyakotey🇬🇭🎹
Nyakotey🇬🇭🎹 - avatar