Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the differences between ES Module and CommonJs in js

Shulou Source: shulou.com Published: 2022-06-03 06:43:47 09月12日 Update

This article mainly talks about "what are the differences between ES Module and CommonJs in js". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what are the differences between ES Module and CommonJs in js?"

1. The process of loading js files in CommonJS module is synchronous and loaded at run time.

2. ES Module loads the js file when compiling (parsing), and it is asynchronous.

3. ES Module derives a reference to the variable itself through export.

Example

Let name = 'coderwhy'; setTimeout () = > {name = "Lakers Champion";}, 1000); setTimeout (() = > {console.log (name);}, 2000); export {name} so far, I believe you have a deeper understanding of "what's the difference between ES Module and CommonJs in js". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Content documents fashion process learning practical deeper interest champion variable example practicality practical easy to operate method is in more friends module website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Linux MariaDB Microsoft