make a function wait for one seconds - Javascript Function

Javascript examples for Function:Function Async

Description

make a function wait for one seconds

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*www . ja va2 s.  co m*/
function sleep (duration) {
    var end = new Date().getTime() + duration;
    while(new Date().getTime() < end) {
      console.log('sleeping');
    }
}
console.log('start: ' + (new Date().toString()));
sleep(1000);
console.log('end: ' + (new Date().toString()));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials