I recently encountered a situation where i have A.js, B.js and C.js . All those JS files importing a same module. ( ex: const hello = require ("hello");
) .
While running them together i get following SyntaxError in the console
Uncaught SyntaxError: Identifier 'home' has already been declared
I'm loading those JS files from HTML using Script tag like below
<script src="../js/A.js"></script>
<script src="../js/B.js"></script>
<script src="../js/C.js"></script>
Moving content of each js file into { }
curly braces is one option to fix the SyntaxError.
But i want to know whether this({}) is right solution or do we have any other better solutions to address this situation