setInterval and setTimeout: timing events – Beau teaches JavaScript



setTimeout and setInterval are timing events in JavaScript that both allow execution of code at specified time intervals. This quick tutorial shows how to use them.

💻 Code: https://codepen.io/beaucarnes/pen/GmzGrg?editors=1011

🐦 Beau Carnes on Twitter: https://twitter.com/carnesbeau

⭐JavaScript Tutorials Playlists⭐
▶JavaScript Basics: https://www.youtube.com/playlist?list=PLWKjhJtqVAbk2qRZtWSzCIN38JC_NdhW5
▶Data Structures and Algorithms: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkso-IbgiiP48n-O-JQA9PJ
▶Design Patterns: https://www.youtube.com/playlist?list=PLWKjhJtqVAbnZtkAI3BqcYxKnfWn_C704
▶ES6: https://www.youtube.com/playlist?list=PLWKjhJtqVAbljtmmeS0c-CEl2LdE-eR_F
▶Clean Code: https://www.youtube.com/playlist?list=PLWKjhJtqVAbkK24EaPurzMq0-kw5U9pJh


Learn to code for free and get a developer job: https://www.freecodecamp.com

Read hundreds of articles on technology: https://medium.freecodecamp.com

And subscribe for new programming videos every day: https://youtube.com/subscription_center?add_user=freecodecamp

source

This Post Has 23 Comments

  1. dekat win

    Just asking to be sure, so set timeout as well as set interval are counting asynchron right ? so i can run othere code while they are sill counting ? Becouse i need somethink like that.

  2. kryyystalball

    'it says hello but it never says goodbye'.
    damn that unexpectedly hit some feelings

  3. Harvester

    Can I stop BLOATWARE this way? If it is possible could you make a video about it?

  4. Kpodji Emmanuel

    i have exams in two hours and you just nailed it. Thanks very much. i watched the video once and just understood everything.👌

  5. Alii

    thanks, I miss the nested settimeout…

  6. ch vishnu

    The given below URL cantians 20 seconds n 120 seconds countdown timer please provide a script 20 to 5 seconds n 120 to 5 or 10 seconds

  7. ch vishnu

    120 to direct 5 seconds countdown timer script provide me Sir

  8. Vitor Peixoto

    I've a question, does setInterval affect the performance of a website?

  9. J3fro C

    So for setTimeout, you perform a function after a certain period ONCE? But with setInterval, you perform a function after a certrain period of time …but does it indefinitely? Is that correct to my understanding?

  10. hwwn

    Thanks Beau, tu es très beau!

  11. Telmo Sampaio

    Thanks Beau, I always used to confused both of this terms 🙂

Leave a Reply