search
HomeWeb Front-endJS TutorialDo script code blocks belong to macro tasks? How does it have to do with macro tasks?

Do script code blocks belong to macro tasks? How does it have to do with macro tasks?

Detailed explanation of the relationship between JavaScript script code block execution mechanism and macro tasks

It is crucial to understand the execution mechanism of script code blocks in JavaScript and their relationship with macro tasks. This article will explore in-depth whether script code blocks belong to macro tasks and explain their execution order.

script code blocks are not macro tasks

Many materials classify script code blocks as macro tasks, but this is not entirely accurate. The execution of script code blocks is synchronous, which is different from the asynchronous execution mechanism of macro tasks. Let's understand it with an example:

 console.log('script1');
Promise.resolve().then(() => { console.log('promise1'); });
console.log('script2');

If script code block is a macro task, the expected output order should be:

 <code>script1 promise1 script2</code>

However, the actual output order is:

 <code>script1 script2 promise1</code>

This is because the browser encounters the HTML when parsing

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft