Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the functions of export and export default

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "what is the role of export and export default". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "what is the role of export and export default" together!

The export command specifies the external interface of the module. A module is an independent file. All variables inside this file cannot be obtained externally. If you want external access to a variable inside a module, you must export the variable using the export keyword. Below is a JS file that uses the export command to output variables.

Use of export

1. directly output

exportletwords='helloworld!!! '

exportfunctionoutput(){

//...

}

2. Define before you export

copy code

letfirstWords='hello'

letsecondWords='world'

letthirdWords='!!! '

functionoutput(){

//...

}

export{firstWords,secondWords,thirdWords,output}

copy code

Use of exportdefault

1.exportdefault Used to specify the default external interface of the module

2. Obviously, there can only be one external interface by default, so exportdefault can only appear once in the same module.

3.exportdefault can only be output directly, can not be defined first and then output.

4. There is also a difference between import and export.

(1)export output and import input

exportfunctionoutput(){

//...

}

import{output}from'./ example'

(2) export default output and import input

exportdefaultfunctionoutput(){

//...

}

importoutputfrom'./ example'

As you can see from the above two import methods, the import method of exportdefault does not need to be wrapped in braces. Because there is only one interface for the output of exportdefault, the default interface of the module is provided, and naturally there is no need to wrap it in braces.

Thank you for reading, the above is "export and export default what is the role" of the content, after the study of this article, I believe that we have a deeper understanding of the role of export and export default, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report