0
0
Typescriptprogramming~5 mins

Default exports vs named exports in Typescript - Quick Revision & Key Differences

Choose your learning style9 modes available
Recall & Review
beginner
What is a default export in TypeScript?
A default export is a single value or entity that a module exports as its main thing. When importing, you can name it anything you want.
Click to reveal answer
beginner
How do you import a default export?
You import a default export using the syntax: <code>import anyName from './module'</code>. The name can be anything you choose.
Click to reveal answer
beginner
What are named exports?
Named exports allow a module to export multiple values by name. When importing, you must use the exact exported names inside curly braces.
Click to reveal answer
beginner
How do you import named exports?
You import named exports using the syntax: <code>import { name1, name2 } from './module'</code>. The names must match exactly.
Click to reveal answer
intermediate
Can a module have both default and named exports?
Yes, a module can have one default export and multiple named exports at the same time.
Click to reveal answer
Which syntax imports a default export from a module?
Aimport * as myThing from './module'
Bimport { myThing } from './module'
Cexport default myThing
Dimport myThing from './module'
How do you import a named export called 'foo'?
Aimport { foo } from './module'
Bimport foo from './module'
Cimport * as foo from './module'
Dexport default foo
Can you rename a default import when importing?
AYes, you can name it anything you want
BNo, you must use the original name
COnly if you use 'as' keyword
DOnly if the module exports multiple defaults
Which statement is true about named exports?
AYou can only have one named export per module
BNamed exports must be imported with the exact exported names
CNamed exports are imported without curly braces
DNamed exports cannot be combined with default exports
Is this valid? export default function() {} and export const foo = 5; in the same file?
ANo, you cannot mix default and named exports
BOnly if you use 'export * from' syntax
CYes, you can have one default and multiple named exports
DOnly if you rename the default export
Explain the difference between default exports and named exports in TypeScript.
Think about how you import and name things from a module.
You got /4 concepts.
    Describe how you would import both a default export and named exports from the same module.
    Remember the syntax differences for default and named imports.
    You got /4 concepts.