Delaying your JavaScript code with the setTimeout() function

preview_player
Показать описание
By using the "setTimeout" method/function in JavaScript, you are able to delay your code from executing, in a time set in milliseconds.

This has a variety of uses, such as controlling interaction within the user interface, showing special content or even developing games.

In this video I take you through a simple example of the "setTimeout" method where we create a button on the page and when pressed, it will show a message to the user. We also then create a second button and through the use of the "clearTimeout" method, we can cancel the rest of the code from executing.

For your reference, check this out:

Support me on Patreon:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

Cheers dcode! As always straight to the point and with the clearest examples. Keep it up!! 👏

marcelapetroli
Автор

the way you say " Alight " is lit

silvernaturemusic
Автор

Excellent explanation, I understand it now :)

marsdwarf
Автор

thanks really for all what you do for us

rollfrollf
Автор

He literally thaught more than he was supposed to.
That's a sub there

aryanagrawal
Автор

FINALY THE LAST PEICE TO MY HUMAN VERIFICATION URL SHORT HTML PROJECT

minecraft-wzfd
Автор

Could someone help me with some JavaScript functions setInterval for my game online ?

acethomas
Автор

Hey im newbie and im trying to make a for loop that won't continue till after the setTimeout has finished but Everytime i try it crashes. Help!!

I do something like
For(var i=0: i<list.length;){
//Stuff
SetTimeout(function (){ stuff(); i++ ;}, 500);
}

butterbot
Автор

Can someone please put in the link for the javascript he used because the program I am using doesn't support setTimeout();

ethansky
Автор

addEventListener? No no just onclick="function()"
<script src="index.js">
Easy

Garfield_Minecraft
Автор

omg is this friend's name DOM????

lgatron