From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Unlock this course with a free trial
Join today to access over 25,000 courses taught by industry experts.
Learn the import and export code in JavaScript - JavaScript Tutorial
From the course: Learn JavaScript: Write Modern Code with JavaScript ESNext
Learn the import and export code in JavaScript
- The next and final ES6 syntax improvement that we're going to look at is improved syntax for sharing code between files. Now, sharing code between files is something we haven't covered yet, so what we're going to do is start off by looking at the old way of importing and exporting code from JavaScript files, and then see what the newer syntax for doing this looks like. We'll start with the syntax for exporting code from JavaScript files. In older versions of JavaScript, this was done using the module.exports syntax, so we could say module.exports equals, and then whatever code we wanted to export from our file. For example, if we wanted to export a function called my func, this syntax defined my func as the file's only export or the so-called default export. And if we wanted to export multiple pieces of code from a single file, for example, several variables or functions, we could do this using so-called named exports from one of our files, which looked like what we see here. We…
Contents
-
-
-
-
-
-
-
-
(Locked)
Learning objectives1m 45s
-
(Locked)
Write functions using arrow syntax4m 22s
-
Set default values for function arguments3m 32s
-
(Locked)
Learn about the spread operator4m 11s
-
(Locked)
Use object destructuring to get object properties3m 53s
-
(Locked)
Use interpolation to insert data into strings1m 44s
-
(Locked)
Learn the import and export code in JavaScript6m 19s
-
(Locked)
-
-
-
-
-
-