0
0
Javascriptprogramming~5 mins

Default exports in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a default export in JavaScript modules?
A default export is a way to export a single value or entity from a module so that it can be imported without using curly braces. It represents the main exported value of the module.
Click to reveal answer
beginner
How do you write a default export for a function named greet?
You write: <pre>export default function greet() {<br>  console.log('Hello!');<br>}</pre> This exports the <code>greet</code> function as the default export.
Click to reveal answer
beginner
How do you import a default export from a module named <code>math.js</code>?
You write: <pre>import anyName from './math.js';</pre> You can choose any name for the imported value because it is the default export.
Click to reveal answer
beginner
Can a module have more than one default export?
No, a module can only have one default export. Trying to export more than one default will cause an error.
Click to reveal answer
intermediate
What is the difference between default export and named export?
Default export exports a single main value without curly braces when importing. Named exports export multiple values and require curly braces when importing.
Click to reveal answer
How do you import a default export from a module?
Aimport { value } from 'module';
Brequire('module').value;
Cimport * as value from 'module';
Dimport value from 'module';
Which of the following is a correct way to export a default value?
Aexport 42 as default;
Bexport { default: 42 };
Cexport default 42;
Dexport default = 42;
Can a module have multiple default exports?
ANo, only one default export is allowed.
BYes, but only two.
CNo, default exports are not allowed.
DYes, unlimited default exports.
What happens if you import a default export with a different name?
AIt causes an error.
BIt works fine; you can rename default imports.
CIt imports nothing.
DIt imports all named exports.
Which syntax imports both default and named exports from a module?
Aimport defaultExport, { namedExport } from 'module';
Bimport { defaultExport, namedExport } from 'module';
Cimport * as all from 'module';
Dimport defaultExport from 'module';
Explain what a default export is and how it differs from named exports.
Think about how you import the main thing from a module.
You got /4 concepts.
    Describe how to export and import a default function from a JavaScript module.
    Focus on the function keyword and import naming.
    You got /3 concepts.