Skip to content

Instantly share code, notes, and snippets.

@Rony20191
Created July 24, 2020 16:46
Show Gist options
  • Save Rony20191/5b883b7cad8073acd19c7f80643445ec to your computer and use it in GitHub Desktop.
Save Rony20191/5b883b7cad8073acd19c7f80643445ec to your computer and use it in GitHub Desktop.
Created TimerJavascript
setTimeout( function() {
console.log( 'Executa uma vez após 1 segundo.' );
}, 1000 );
setInterval( function() {
console.log( 'Executa infinitamente, 1 vez por segundo.' );
}, 1000 );
/*
setInterval() executa infinitamente, até que você execute clearInterval();
setTimeout() executa apenas uma vez.
*/
var counter = 0;
var timer = setInterval(function() {
if( counter >= 10 ) {
clearInterval( timer );
}
console.log( counter++ );
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment