Challenge - 5 Problems
Export Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this ES module export-import code?
Consider two files:
module.js:
main.js:
What will be printed when running
module.js:
export const a = 5; export const b = 10;
main.js:
import { a, b } from './module.js';
console.log(a + b);What will be printed when running
main.js?Javascript
export const a = 5; export const b = 10; // In main.js import { a, b } from './module.js'; console.log(a + b);
Attempts:
2 left
💡 Hint
Remember that named exports can be imported by their exact names.
✗ Incorrect
The variables 'a' and 'b' are exported and imported correctly. Their values 5 and 10 add up to 15, which is printed.
❓ Predict Output
intermediate2:00remaining
What does this default export import print?
Given
module.js:
main.js:
What will be the output when running
module.js:
const greeting = 'Hello World'; export default greeting;
main.js:
import greet from './module.js'; console.log(greet);
What will be the output when running
main.js?Javascript
const greeting = 'Hello World'; export default greeting; // In main.js import greet from './module.js'; console.log(greet);
Attempts:
2 left
💡 Hint
Default exports can be imported with any name.
✗ Incorrect
The default export is the string 'Hello World'. It is imported as 'greet' and logged, so output is 'Hello World'.
❓ Predict Output
advanced2:00remaining
What error does this code produce?
Look at this code in
And this in
What happens when running
module.js:export const x = 10; export default 20;
And this in
main.js:import { x, default as y } from './module.js';
console.log(x + y);What happens when running
main.js?Javascript
export const x = 10; export default 20; // In main.js import { x, default as y } from './module.js'; console.log(x + y);
Attempts:
2 left
💡 Hint
You cannot import default export using named import syntax.
✗ Incorrect
The syntax 'import { default as y }' is invalid. Default exports must be imported without curly braces or renamed differently.
❓ Predict Output
advanced2:00remaining
What is the output of this re-exporting code?
Given three files:
file1.js:
file2.js:
main.js:
What will be printed when running
file1.js:
export const num = 7;
file2.js:
export { num } from './file1.js';main.js:
import { num } from './file2.js';
console.log(num);What will be printed when running
main.js?Javascript
// file1.js export const num = 7; // file2.js export { num } from './file1.js'; // main.js import { num } from './file2.js'; console.log(num);
Attempts:
2 left
💡 Hint
Re-exporting passes the export through another module.
✗ Incorrect
The variable 'num' is exported from file1.js, re-exported by file2.js, and imported in main.js. The value 7 is logged.
❓ Predict Output
expert2:00remaining
What is the output of this dynamic import code?
Consider this code in
And
What will be printed when running
main.js:async function load() {
const module = await import('./module.js');
console.log(module.value);
}
load();And
module.js:export const value = 42;
What will be printed when running
main.js with Node.js supporting ES modules?Javascript
async function load() { const module = await import('./module.js'); console.log(module.value); } load();
Attempts:
2 left
💡 Hint
Dynamic import returns a promise resolving to the module object.
✗ Incorrect
The dynamic import loads the module asynchronously. The exported 'value' is 42, which is logged.