Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6 Modules lesson: Remove variable's name in export default examples and edit description #28674

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions javascript/organizing_your_javascript_code/es6_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ In the above, we are not exporting an object containing `greeting` and `farewell

In contrast to named exports, a file can only default export a single thing. Something exported this way does not have a name attached to it, so when you import it somewhere, you can decide what name to give it.

To export something from a file as a default export, we can also do it inline by prepending `export default` to the appropriate declaration, or we can export it at the end of the file, this time *without* any curly braces. Again, either way is perfectly fine. Note that if you do an inline default export, if you would normally declare with `let` or `const`, the `default` keyword *replaces* `let`/`const`.
To export something from a file as a default export, we can also do it inline by prepending `export default` to the appropriate declaration, or we can export it at the end of the file, this time *without* any curly braces. Again, either way is perfectly fine. Note that if you want to inline default export a variable, the `default` keyword *replaces* the variable declaration so you export the expression directly.

Let's default export our greeting string from `one.js`.

```javascript
// one.js
export default greeting = "Hello, Odinite!";
export default "Hello, Odinite!";
```

Or on a separate line:
Expand All @@ -168,7 +168,7 @@ Let's default export the greeting string from `one.js`, and export the farewell

```javascript
// one.js
export default greeting = "Hello, Odinite!";
export default "Hello, Odinite!";
export const farewell = "Bye bye, Odinite!";
```

Expand Down
Loading