| 12345678910111213141516171819202122232425262728293031 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // js 是单线程的 分为 同步任务 异步任务
- // 同步任务 按照顺序执行 必须等待上一个任务执行完毕 才能执行下一个任务
- // 异步任务 不按照顺序执行 不会阻塞后续任务的执行 会进入到任务队列中 等待同步任务执行完毕后 再执行异步任务
- // console.log(3);
- // setTimeout(function(){
- // console.log(1);
- // },1000)
- // console.log(2);
- // js执行过程中无论异步代码需要等多久都会先执行同步任务
- // 同步任务执行完毕后 才会执行异步任务
- // 常见的异步方法:
- // 定时函数 setTimeout setInterval
- console.log(3);
- setTimeout(function(){
- console.log(1);
- },0);
- console.log(2);
- </script>
- </body>
- </html>
|