'How to delay the next command in javascript? [duplicate]

I am stuck in a situation where I want to put some delay between some lines of javascript code like following :

function sayHello(){
document.getElementById("txt").innerHTML = "Hello";
// some delay of about 2 seconds 
document.getElementById("txt").innerHTML = "I am a programmer";

}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source