Add Pause in JavaScript script

Working to a JS script, I wanted to add a pause in the execution of the script.
In PHP there is a function sleep() to delay execution of the PHP script, but JavaScript doesn't have such a function.
Looking on the net, I found a solution to delay the execution of some code in JS script, by using the setTimeout() function.

Here's the method, the code that must be executed after pause must be inside a function that will be accessed with setTimeout():

setTimeout( function() {
  // here add the code (or call a function) to be executed after pause
}, 1000 );
- 1000 represents the number of millisecond of the pause (for 2 seconds add 2000).

Here is an example, show two messages with alert(), the second alert will be displayed after a pause of 2 seconds.
<script type="text/javascript"><!--
function testPause(Pause) {
  alert('Hi there');
  setTimeout( function() {
    // code that must be executed after pause
    alert('Hi, I came after 2 seconds');
  }, Pause );
}

testPause(2000);
--></script>

To test this example, click .

Here is another example that adds a "Loading ..." message into an HTML element, than, after 1.5 seconds displays a content.
<div id="cnt"> </div>
<script type="text/javascript"><!--
function simLoad(id) {
  // display 'Loading ..', and use setTimeout() to access a function after 1.5 seconds
  document.getElementById(id).innerHTML = '<h4>Loading ...</h4>';
  setTimeout(function() { adContent(id); }, 1500);

  /* in this case setTimeout() can be used also like this
      setTimeout("adContent('"+id+"')", 1500);
  */
}

// this function adds a content inside a HTML element, with the ID passed in parameter
function adContent(id) {
  document.getElementById(id).innerHTML = 'JavaScript Tutorial - <i>Pause the script in JS</i> - <a href="http://coursesweb.net/javascript/" title="JavaScript Course">JavaScript Course</a>';
}

simLoad('cnt');        // access simLoad() with the ID of HTML tag
--></script>

To test this example, click .