The difference between export and export default in JavaScript ES6

Source: Internet
Author: User

I believe many people have used export, export default, import, but what is the difference between them?
In JavaScript ES6, export and export default can be used for exporting constants, functions, files, modules, etc., which you can import in other files or modules in such a way that they can be import+(常量 | 函数 | 文件 | 模块)名 used, but in a file or module, Export, import can have multiple, export default only one.
Specific use:
1.

//demo1.jsexport const str = ‘hello world‘export function f(a){ return a+1}

The corresponding import method:

//demo2.jsimport { str, f } from ‘demo1‘ //也可以分开写两次,导入的时候带花括号

2.

//demo1.jsexport default const str = ‘hello world‘

The corresponding import method:

//demo2.jsimport str from ‘demo1‘ //导入的时候没有花括号

原文地址http://blog.csdn.net/zhou_xiao_cheng/article/details/52759632

The difference between export and export default in JavaScript ES6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.