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.

HTML demo of the snippet

 * 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)

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