0
0
Javascriptprogramming~5 mins

Exporting values in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of exporting values in JavaScript modules?
Exporting values allows you to share variables, functions, or objects from one file so other files can use them.
Click to reveal answer
beginner
How do you export a single value as the default export in JavaScript?
Use export default followed by the value, for example: export default function() {}.
Click to reveal answer
intermediate
What is the difference between named exports and default exports?
Named exports let you export multiple values by name, while default export lets you export one main value per module.
Click to reveal answer
beginner
How do you export multiple values from a module?
You list them inside curly braces after the export keyword, like export { a, b, c }.
Click to reveal answer
beginner
Can you export a value immediately when declaring it? Give an example.
Yes, for example: <code>export const pi = 3.14;</code> exports the constant <code>pi</code> right away.
Click to reveal answer
Which keyword is used to export a value from a JavaScript module?
Aimport
Brequire
Cmodule
Dexport
How do you export a function as the default export?
Aexport default function myFunc() {}
Bexport function myFunc() {}
Cexport { myFunc }
Ddefault export function myFunc() {}
Which syntax exports multiple named values at once?
Aexport default { a, b }
Bexport (a, b)
Cexport { a, b }
Dexport a, b
Can a module have more than one default export?
ANo, only one default export
BYes, but only two
CYes, unlimited
DOnly if named
What does this code do? export const name = 'Alice';
AImports a constant named name
BExports a constant named name
CDeclares a variable without exporting
DExports a default value
Explain how to export multiple values from a JavaScript module and how to import them.
Think about curly braces and matching names.
You got /3 concepts.
    Describe the difference between default export and named export with examples.
    One uses 'export default', the other uses 'export { }'.
    You got /3 concepts.