• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

The Coding Couple

Pair programming is a lifetime commitment.

  • Home
  • Categories
    • Arduino
    • JavaScript
    • Python
    • Raspberry Pi
  • About Us
    • Privacy Policy
  • Contact

.mjs extension (A JavaScript module file) | Today I Learned

November 12, 2019 by Ashley

Today, I needed to reference the MDN docs for JavaScript modules. As I skimmed through the page, something caught my eye: a file name with the .mjs extension.

Source

My first reaction was confusion. This was my first time seeing a file with that extension. Upon further reading, I learned .mjs is a special JavaScript file extension to indicate the script uses native JavaScript modules. Hence the “m” prefix to the “js”.

Reasons for using .mjs as opposed to .js

  • For clarity. The .mjs file extension is a quick way to indicate the code in the file uses JavaScript modules instead of classic JavaScript.
  • For parsing. The .mjs file extensions lets runtime environments (ie Node.js) and build tools (ie. Babel) know the file should be parsed as a module.
  • Avoids strict MIME type errors. Files with the .mjs extension are imported with the javascript/esm MIME-type.

I haven’t written a native JavaScript module (also referred to as ES Module) before, so all this was news to me. It’s nice to see some browser support for JavaScript modules without the need for third party dependencies.

Additional Reading

  • MDN Web Docs: JavaScript modules
  • Using JS modules in the browser

Related Posts

  • Avoid using mutable values as default parameter values in Python (Today I Learned)Avoid using mutable values as default parameter values in Python (Today I Learned)
  • There’s a name for that:  the Kebab CaseThere’s a name for that: the Kebab Case
  • Pokémon Color Picker | A web app built with HTML/CSS + JavaScriptPokémon Color Picker | A web app built with HTML/CSS + JavaScript
  • Fractions in Python | Today I LearnedFractions in Python | Today I Learned
  • Getting started with Phaser and ES2015Getting started with Phaser and ES2015
  • Surviving the Hackathon:  Angular Attack 2016Surviving the Hackathon: Angular Attack 2016

Filed Under: JavaScript, Programming Languages, Today I Learned Tagged With: .mjs, javascript, module, TIL, today I learned, web development

Previous Post: « Vue.JS Error: This relative module was not found
Next Post: Fractions in Python | Today I Learned »

Primary Sidebar

Social Media

  • GitHub
  • Instagram
  • Twitter
  • YouTube

Recent Posts

  • Pokémon Color Picker | A web app built with HTML/CSS + JavaScript
  • Pokéball Single DIV CSS Drawing | Tutorial
  • Error: [🍍]: “getActivePinia()” was called but there was no active Pinia
  • Trijam #261 Game Jam Diary: One Wrong Move
  • Using WSL on Corporate VPN

Recent Comments

  • Lizzy on Creation Crate Month 2: An Arduino Powered Memory Game
  • Ashley Grenon on Creation Crate Month 2: An Arduino Powered Memory Game
  • Lizzy on Creation Crate Month 2: An Arduino Powered Memory Game
  • kelly on Creation Crate Month 2: An Arduino Powered Memory Game
  • Ashley on Creation Crate Month 3: An Arduino Powered Distance Detector

Follow us on Instagram!

This error message is only visible to WordPress admins

Error: No feed found.

Please go to the Instagram Feed settings page to create a feed.

Categories

  • Arduino
  • Conferences
  • Debugging
  • Game Jams
  • HTML and CSS
  • JavaScript
  • Programming Languages
  • Python
  • Raspberry Pi
  • Today I Learned

Archives

  • May 2024
  • April 2024
  • March 2024
  • May 2022
  • December 2021
  • May 2021
  • March 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • June 2019
  • April 2019
  • September 2017
  • April 2017
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • April 2015
  • January 2015

Tags

adafruit arduino brackets c# code smell codestock coding standards conventions creation crate debugging developer devspace electronics es6 es2015 game development game jam gotcha hackathon hoisting html html5 javascript led naming conventions nintendo phaser pluralsight pokemon programmer python raspberry pi retro retropie scope self improvement single div single div drawing subscription box TIL today I learned troubleshooting vue vuejs windbg

Footer

About Us

We are the Coding Couple.  Two people who met in college and decided they wanted to pair program for the rest of their ...

Read More »

Most Recent Posts

Pokémon Color Picker | A web app built with HTML/CSS + JavaScript

Pokéball Single DIV CSS Drawing | Tutorial

Error: [🍍]: “getActivePinia()” was called but there was no active Pinia

Trijam #261 Game Jam Diary: One Wrong Move

Social Media

  • GitHub
  • Instagram
  • Twitter
  • YouTube

Copyright Notice

© The Coding Couple, 2015 – 2023. Excerpts and links may be used, provided that full and clear credit is given to The Coding Couple with appropriate and specific direction to the original content.

Copyright © 2025 · Foodie Pro Theme by Shay Bocks · Built on the Genesis Framework · Powered by WordPress