JavaScript Modules with Import/Export Syntax (ES6) – JavaScript Tutorial




In this video I’ll be showing you how to use native JavaScript Modules with the import and export syntax in JavaScript – this works on major browsers such as Chrome, Firefox, Safari and Edge.

Modules allow you to separate your code into individual chunks or components, allowing for easier maintainability and better file organization.

Support me on Patreon:
https://www.patreon.com/dcode – with enough funding I plan to develop a website of some sort with a new developer experience!

For your reference, check this out:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

Follow me on Twitter @dcodeyt!

If this video helped you out and you’d like to see more, make sure to leave a like and subscribe to dcode!

Original source


30 responses to “JavaScript Modules with Import/Export Syntax (ES6) – JavaScript Tutorial”

  1. hi my browser says " index.html:1 Access to script at 'file:///C:/Users/User/Desktop/Learning/js/main.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. " and I cannot use modules like you teach. any help?

  2. How would we import an npm package if using an npm init setup? Import doesnt work in that scenario, I have tried afew and used for example: import axios from '../node_modules/axios/dist/axios.js'; and get a console error saying it does not provide an export named 'default'.

  3. i tried to use this feature i get a message "Access to script at [path to root js file] from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https."

  4. Im having one question what if we want to use the water fn from helper .js in utils.js…So for that we have to import fn water in util.js right? or by simple exporting the fn water in util.js will solve the problem..
    please clarify the doubt im bit confused now

  5. i appreciate this video man. i learned quite a bit. but what if i want to use the javascript from the 'main.js' on my actual HTML page. Im using the import/export method to export a Player Class into a 'main.js' file and then instatiating a player object into the main.js file. i can console.log player stats and stuff but i cant document.write player stats in the main.html page. it says player is undefined.

Leave a Reply