What is the difference between .js and .mjs files?

前端 未结 3 620
隐瞒了意图╮
隐瞒了意图╮ 2021-01-01 09:01

I have started working on an existing project based on Node.js. I was just trying to understand the flow of execution, where I encountered with some *.mjs files

3条回答
  •  隐瞒了意图╮
    2021-01-01 09:06

    For clarity. As for devs/humans, it's easy to distinguish between a module file(.mjs) and a normal javascript file(.js)... because it's not always easy to determine even if you examine the code in the file.

    There are also performance benefits which gives you more reason to consider using it. V8(JavaScript engine that powers Google Chrome) recommends the use of .mjs but it still depends on your situation. If you want to know more of it's advantages, check https://v8.dev/features/modules#mjs

提交回复
热议问题