1

Is everything in ES6 part of module. eg. if I write in a file.

function simpleFunc(){ console.log("test") } 

Is this function not available to code in other places. In regular javascript , this function can also be executed from within html script.

What is the whole concept of modules. I understand polluting global namespace is a bad practice , but when we export a function or const, is it just an approach to avoid polluting global namespace. Can a developer still write var a= 10 in a js file and waste all the efforts of maintaining modules. I suppose this would still be possible because es6 is supposed to be backwards compatible with js.

Simply my question boils down to: Is a js file different when the language is ES6.

1 Answer 1

2

Not sure why no-one has answered this question yet, it's a simple answer, so I will answer it in case anyone else stumbles onto it:

Javascript is javascript.

ES5 practices still apply to ES6 in terms of script placement. Modularization allows you to import code from one script to another - this can help you keep large applications maintainable as well as many other structural benefits. Additionally you are right about not polluting the global namespace - modules are also namespace containers, which protects the global namespace.

Here's a quote from a good (full) explanation to the importance of modules:

Modularization is the basic necessity for any software development. Breaking things into smaller pieces of functionality gives us the power to reuse the code. Modules are also containers for the namespaces.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.