SetTimeout (CB, MS)
The setTimeout (CB, MS) global function executes the specified function (CB) After the specified number of milliseconds (ms). : SetTimeout () executes the specified function only once.
Returns a handle value representing the timer.
Instance
To create the file main.js, the code looks like this:
functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionSetTimeout(Printhello, -);
Execute the main.js file, as shown in the following code:
$ node Main . JS Hello , World !
Cleartimeout (t)
The cleartimeout (t) global function is used to stop a timer that was previously created by SetTimeout (). The parameter T is a timer created by the SetTimeout () function.
Instance
To create the file main.js, the code looks like this:
functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionvarT=SetTimeout(Printhello, -);//Clear Timercleartimeout(T);
Execute the main.js file, as shown in the following code:
$ node Main . JS
SetInterval (CB, MS)
The setinterval (CB, MS) global function executes the specified function (CB) After the specified number of milliseconds (ms).
Returns a handle value representing the timer. You can use the clearinterval (t) function to clear the timer.
The SetInterval () method keeps calling functions until Clearinterval () is called or the window is closed.
Instance
To create the file main.js, the code looks like this:
functionPrinthello(){Console.Log("Hello, world!.");}///After two seconds to execute the above functionsetinterval(Printhello, -);
Execute the main.js file, as shown in the following code:
$ node Main . JS
Hello, world!. Hello, world!. Hello, world!. Hello, world!. Hello, world!. ......
The above program will output "Hello, world!" every two seconds, and will be executed permanently until you press CTRL + C button.
SetTimeout, Cleartimeout, setinterval