How to clear setTimeout() in JavaScript?
In order to clear setTimeout()
:
- Assign the
setTimeout()
to the variable. - Use the
clearTimeout()
function on the variable.
Example:
<script>
var myTimeout = setTimeout(function() {
console.log('test');
}, 500)
clearTimeout(myTimeout);
</script>