fix/add-anonymous-function-example
This commit is contained in:
committed by
Kristofer Koishigawa
parent
9c1b83dd0c
commit
2e49aa02df
@ -8,12 +8,18 @@ challengeType: 1
|
|||||||
<section id='description'>
|
<section id='description'>
|
||||||
In the <code>export</code> lesson, you learned about the syntax referred to as a <dfn>named export</dfn>. This allowed you to make multiple functions and variables available for use in other files.
|
In the <code>export</code> lesson, you learned about the syntax referred to as a <dfn>named export</dfn>. This allowed you to make multiple functions and variables available for use in other files.
|
||||||
There is another <code>export</code> syntax you need to know, known as <dfn>export default</dfn>. Usually you will use this syntax if only one value is being exported from a file. It is also used to create a fallback value for a file or module.
|
There is another <code>export</code> syntax you need to know, known as <dfn>export default</dfn>. Usually you will use this syntax if only one value is being exported from a file. It is also used to create a fallback value for a file or module.
|
||||||
Here is a quick example of <code>export default</code>:
|
Here is a couple examples using <code>export default</code>:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
// named function
|
||||||
export default function add(x, y) {
|
export default function add(x, y) {
|
||||||
return x + y;
|
return x + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// anonymous function
|
||||||
|
export default function(x, y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Since <code>export default</code> is used to declare a fallback value for a module or file, you can only have one value be a default export in each module or file. Additionally, you cannot use <code>export default</code> with <code>var</code>, <code>let</code>, or <code>const</code>
|
Since <code>export default</code> is used to declare a fallback value for a module or file, you can only have one value be a default export in each module or file. Additionally, you cannot use <code>export default</code> with <code>var</code>, <code>let</code>, or <code>const</code>
|
||||||
|
Reference in New Issue
Block a user