The Module System: A JavaScript Tale

Adriano Marques
CEO at XNV

JavaScript is an alive language. And a relatively new one, too. That is really relevant information when it comes to explaining some questions that we naturally stumble upon when diving deeper in our journey to master it.

For example, a single question that once stuck to my mind was: Why do we sometimes use “const … = require(…)” and in other occasions “from … import …”? As a developer whose first language was Python, those kind of particularities has always intrigued me a lot. I couldn’t seem to understand why there was more than one way of doing things, but most importantly, why did sometimes one way or another wouldn’t work right away.

Of course, first of all we are programmers. Problem solvers. For that very reason, it is common for us to focus a lot more in the technical aspects of our target programming language, many times not knowing its history. And that makes sense. After all, we got problems to solve and that’s what pays our bills in the end of the month. However, there are sometimes when a bit o historical context can give us a great advantage in understanding why does one feature works the way it does. Talking about JavaScript, the module system couldn’t be a better example of this.

If you are -like me- a developer, you’re probably very familiarized with the idea of modularization and why it is so important for us. Basically, when we have a more complex application we want to have it all organized in smaller files, so that we can easily reuse logic, components, functions, and also having a happier experience when the time comes to refactor some functionality. Until now, I’m not saying anything new to you, am I? I hope not. Anyway, here’s the catch: JavaScript was never intended to make use of this modularization.

THE BLOG

News, lessons, and content from our companies and projects.

Stay In The Loop!

Receive updates and news about XNV and our child companies. Don't worry, we don't SPAM. Ever.