Executing JavaScript code at some point with setTimeout

Published on 2020-05-02 • Modified on 2020-05-02

This is a classical JavaScript snippet; I wanted to have it here on my blog with a live demo. Click on the button to trigger an alert with a two seconds delay.


/**
 * I am using a JavaScript module to isolate the code of each snippet.
 * In fact it's a Vue.js mixin. Take the code called by the mounted()
 * or the snippetXX() function.
 */
export default {
  methods: {
    snippet88 () {
      setTimeout(function () {
        alert('Hello world! 🐝')
      }, 2000)
    }
  }
}
HTML demo of the snippet

 More on Stackoverflow   Read the doc  More on the web  Random snippet

  Work with me!


Call to action

Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )

Thank you for reading! And see you soon on Strangebuzz! 😉

COil