setTimeout(myFunction, 5000); vs setTimeout(myFunction(), 5000);

后端 未结 3 826
忘了有多久
忘了有多久 2021-01-21 13:27

I was playing around with the \"setTimeout\" function. This code runs like expected:

function myFunction() {
    console.log(\'test\');
    setTimeout(myFunction         


        
3条回答
  •  感情败类
    2021-01-21 13:53

    myFunction() calls the function immediately and passes its return value to setTimeout to be called later (except its return value is undefined, which isn't a function (or a string), so that is pointless).

提交回复
热议问题