JAVASCRIPT JOURNEY - DAY 10

#teamtanayejschallenge

CHAPTER 10: MODULES

images.jpg

When JavaScript appeared on browsers it was added with script tags and every function or variable was global.

That was easy for smaller projects but made it difficult to reuse code created by different teams,

because some functions or variables could be unintentionally shared or overridden between different libraries.

Modules are an attempt to avoid these problems.

A module is a piece of program that specifies which other piece to relies on and which functionality it provides for other modules to use.

It is of more use in NODEJS IMPLEMENTATION.

“modules” refers to small units of independent, reusable code. They are the foundation of many JavaScript design patterns.

In simpler terms, modules help you to write code in your module and expose only those parts of the code that should be accessed by other parts of your code.

You cannot include trillions of script tags inside HTML FILE to refer intercommunication.

<script src="app.js"></script>
<script src="search.js"></script>
<script src="user.js"></script>
<script>
console.log('inline code');
</script>

This is a very bad practice as each script initiates a new HTTP request, which affects page performance badly.

2da99bc4-0258-479b-9a67-d257ebe10a3d.jpg

ADVANTAGES:

Code can be split into smaller files of self-contained functionality.

Multiple scripts can be concatenated thereby increasing performance.

Debugging becomes easier.

ES6 modules help you to organize your code better.

We will get its more use during NODEJS in-detail coding.

Happy Learning-)