eajni IT 초보사전 💦💦

[JavaScript] 자바스크립트 기초 (모듈)

2023-07-29

Modules

  • to break up your code into separate files
  • Modules are imported from external files with the import statement.
    <script type="module">
    //import from named export
    import {name, age} from "./person.js"; 
    //import from default export
    import personalInfo from "./personalInfo.js"; 
    </script>
    

    Export

    Named Exports

  • individually
    //person.js
    export const name = "Mina";
    export const age = 22;
    
  • all at once at the bottom ```js const name = “Mina”; const age = 22;

export {name, age}; ```

Default Exports

```js const personalInfo = () => { const name = “Mina”; const age = 22; return name + ‘ is ‘ + age + “years old”; };

export default personalInfo;


Comments

Content