[Learning]#27 JS: Timing Events — Part 1

Vida Lin
Oct 17, 2021

What is timing event?

“JavaScript can be executed in time-intervals. This is called timing events.
The window object allows execution of code at specified time intervals.
These time intervals are called timing events.
The two key methods to use with JavaScript are:

  • setTimeout(function, milliseconds)
    Executes a function, after waiting a specified number of milliseconds.
  • setInterval(function, milliseconds)
    Same as setTimeout(), but repeats the execution of the function continuously."

by W3C School

Basic timing event

<script type="text/javascript">
function init(){
window.setTimeout(countdown, 1000);
}
function countdown (){
alert("Hi there!");
}
</script>

The unit is milliseconds, so 1000 milliseconds = 1 second.

The window will popup in 1 second.

Music of Today: Strangers In A Dream by Phum Viphurit

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Vida Lin
Vida Lin

Written by Vida Lin

PM, Relationship, Travel, or anything quirky but interesting.|Subscribe & buy Vida a drink @LikerLand, the bottom of each article. 在文章底下LikerLand訂閱、請Vida喝一杯飲料 ❤

No responses yet

Write a response