Modules
Learn how to use JavaScript modules, a way to define reusable logic in your programs.
StartKey Concepts
Review core concepts you need to learn to master this subject
Import Javascript modules with the require function
Javascript export default
Intermediate Javascript: Export Module
Using the import keyword in Javascript
Import Javascript modules with the require function
Import Javascript modules with the require function
var moduleA = require( "./module-a.js" );
// The .js extension is optional
var moduleA = require( "./module-a" );
// Both ways will produce the same result.
// Now the functionality of moduleA can be used
console.log(moduleA.someFunctionality)
In Node.js, the require
function can used to import code from another file into the current script.
What you'll create
Portfolio projects that showcase your new skills
Message Mixer
It's time to build fluency in JavaScript Modules. In this next Pro Project, we're going to practice function importation in JavaScript so you can hone your skills and feel confident taking them to the real world. Why? You don't want to copy and paste your functions from file to file. Learn to reuse them by importing. What's next? A mixer, creating goofy sentences, and more JavaScript. You got this!
WorkAround
It's time to build fluency in JavaScript Modules. In this next Pro Project, we're going to practice importing and exporting data in JavaScript so you can hone your skills and feel confident taking them to the real world. Why? Helper functions can keep your code clean and provide data from an entirely different file. What's next? Salaries, replacing your calculator with automation, more JavaScript. You got this!
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory