Learn JavaScript setTimeout() in 6 minutes! ⏰

preview_player
Показать описание
00:00:00 introduction
00:00:30 setTimeout w/ callback
00:01:04 setTimeout w/ anonymous functions
00:01:25 setTimeout w/ arrow funcitons
00:01:43 clearTimeout()
00:02:32 start button
00:03:51 clear button
00:05:49 conclusion

// setTimeout() = function in JavaScript that allows you to schedule
// the execution of a function after an amount of time
// Times are approximate
// setTimeout(callback, delay);

function hello() {
}

setTimeout(hello, 3000);
Рекомендации по теме
Комментарии
Автор

// setTimeout() = function in JavaScript that allows you to schedule
// the execution of a function after an amount of time
// Times are approximate
// setTimeout(callback, delay);

// EXAMPLE 1
function hello() {
window.alert("Hello");
}

setTimeout(hello, 3000);

// EXAMPLE 2
// clearTimeout() = can cancel a timeout before it triggers

const timeoutId = setTimeout(() => window.alert("Hello"), 3000);

clearTimeout(timeoutId);

// EXAMPLE 3

let timeoutId;

function showAlert() {
window.alert("Hello");
}

function startTimer() {
timeoutId = setTimeout(showAlert, 3000);
console.log("STARTED");
}

function clearTime() {
clearTimeout(timeoutId);
console.log("CLEARED");
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<button
<button
<script src="index.js"></script>
</body>
</html>

BroCodez
Автор

I changed "hello" to "too late" so its like you make a game to press clear before the pop up window comes out and says "too late"

nicktorius
Автор

1 thousand nah 1 1 thousand, 2 thousand nah 2 1 thousand

futuredoctor
Автор

Hi, the statment "function clearTime() {"
must be: "function clearTimer() {"

mazinhussein
Автор

hey bro, what do you think is a project i could try doing with all of the things we've learned?

hunin