0
0
Typescriptprogramming~20 mins

Default exports vs named exports in Typescript - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Export Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of importing default export
What will be the output of this TypeScript code when run?
Typescript
export default function greet() {
  return "Hello from default export!";
}

import greet from './module';
console.log(greet());
A"Hello from default export!"
BTypeError: greet is not a function
Cundefined
DSyntaxError: Unexpected token import
Attempts:
2 left
💡 Hint
Default exports can be imported with any name without braces.
Predict Output
intermediate
2:00remaining
Output of importing named export
What will be the output of this TypeScript code when run?
Typescript
export function greet() {
  return "Hello from named export!";
}

import { greet } from './module';
console.log(greet());
ASyntaxError: Unexpected token import
BTypeError: greet is not a function
Cundefined
D"Hello from named export!"
Attempts:
2 left
💡 Hint
Named exports must be imported with braces and exact names.
Predict Output
advanced
2:00remaining
What happens if you import a named export as default?
Given this module code, what will be the output or error when running the import code?
Typescript
export function greet() {
  return "Hello!";
}

import greet from './module';
console.log(greet());
A"Hello!"
BSyntaxError: Cannot use import statement outside a module
CTypeError: greet is not a function
Dundefined
Attempts:
2 left
💡 Hint
Default import expects a default export, but only named export exists.
🧠 Conceptual
advanced
2:00remaining
Difference in importing multiple named exports vs default export
Which statement correctly describes the difference between importing multiple named exports and a default export in TypeScript?
ANamed exports can only be imported one at a time; default exports can import multiple items.
BMultiple named exports must be imported with braces and exact names; default export is imported without braces and can be renamed freely.
CBoth default and named exports must be imported with braces and exact names.
DDefault exports must be imported with braces; named exports are imported without braces.
Attempts:
2 left
💡 Hint
Think about how you write import statements for default vs named exports.
Predict Output
expert
3:00remaining
Output of combined default and named exports import
What will be the output of this TypeScript code when run?
Typescript
export default function greet() {
  return "Hello from default!";
}

export function greetNamed() {
  return "Hello from named!";
}

import greet, { greetNamed } from './module';
console.log(greet());
console.log(greetNamed());
A
"Hello from default!"
"Hello from named!"
B
"Hello from named!"
"Hello from default!"
CTypeError: greet is not a function
DSyntaxError: Unexpected token import
Attempts:
2 left
💡 Hint
You can import default and named exports together in one statement.