Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
Is async callback happening with setInterval() here?

I'm making a rookie second stopwatch here only using setInterval.

I tried to visually stop the stopwatch from counting up by artificially overriding the innerHTML of the timer display, which I know is pretty dumb.

When I un-pause the stopwatch, the display increments more than one count every second, which is quite interesting. I'd like to know why this happens - is it because the countedTime still runs in the event queue, while the startStopwatch() refreshes the display every second?

Is this what they call an async callback?

var countedTime = 0
var paused

// specify HTML areas for components
const displayArea = document.querySelector("#timer-display")
const countUpButton = document.querySelector("#count-up-button")
const pauseButton = document.querySelector("#pause-button")


// increment timer by 1 second 

function countUp() {
    if (paused === false) {
    countedTime += 1
    displayArea.innerHTML = countedTime
    }
}

// function to begin counting up

function startStopwatch() {
    paused = false
    setInterval(countUp, 1000)
}

countUpButton.addEventListener("click", startStopwatch);

// add pause button

function pauseStopwatch() {
    paused = true
}

pauseButton.addEventListener("click", pauseStopwatch)
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda