Home > Web Front-end > JS Tutorial > body text

What is \'export default\' and How is it Different from \'module.exports\'?

DDD
Release: 2024-10-17 23:01:29
Original
228 people have browsed it

What is

ES6's "export default" Explained

JavaScript's ES6 module system introduced "export default," a unique way of defining a default export for a module.

In the example provided, the file SafeString.js defines a SafeString class and exports it as the default export using:

export default SafeString;
Copy after login

This default export can be imported from another module by using the following syntax:

import SafeString from './SafeString.js';
Copy after login

Equivalent Syntax

Before ES6, there was no direct equivalent to "export default." However, a similar approach could be achieved using "module.exports:"

module.exports = SafeString;
Copy after login

This would assign the SafeString class to the module object, allowing other modules to access it.

The above is the detailed content of What is \'export default\' and How is it Different from \'module.exports\'?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!