what is setTimeOut() function in javascript?

前端 未结 4 1677
粉色の甜心
粉色の甜心 2020-12-19 21:55

Can i ask what the function of setTimeOut method in javascript?As below:

function startTime()
{
var today=new Date();
var h=today.getHours();
var m=today.get         


        
4条回答
  •  别那么骄傲
    2020-12-19 22:43

    setTimeout() just schedules (sets a timer for) a function to execute at a later time, 500ms in this case. In your specific code, it's updating the screen with the current time every half-second (it only schedules one call, 500ms from now...but that startTime call scheduled another).

    Also...passing a string to it when you can avoid it is bad practice, for your example it should be:

    t = setTimeout(startTime, 500);
    

提交回复
热议问题