HTML/Html-Javascript/31-同步异步的认识.html

53 lines
885 B
HTML
Raw Normal View History

2023-05-01 19:37:40 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 从上到下 从左到右
// 同步
// console.log("start");
// // N
// console.log("end");
// 异步
// 定时器, Ajax 读取文件,
console.log("start");
// 异步代码
setTimeout(() => {
console.log("内容");
}, 0);
throw 'stop'
console.log("end");
</script>
</body>
</html>
<!--
如何区分异步API与同步API
看 这个API 需不需要 等待时间
看 这个API 需不需要 等待时间是确定的吗(不是人为确定 是机器内部确定)
-->