0
0
Javascriptprogramming~20 mins

Exporting values in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Export Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ES module export-import code?
Consider two files:
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);
ANaN
Bundefined
C15
DReferenceError
Attempts:
2 left
💡 Hint
Remember that named exports can be imported by their exact names.
Predict Output
intermediate
2:00remaining
What does this default export import print?
Given
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);
AHello World
Bundefined
CReferenceError
Dgreet
Attempts:
2 left
💡 Hint
Default exports can be imported with any name.
Predict Output
advanced
2:00remaining
What error does this code produce?
Look at this code in 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);
ASyntaxError
BTypeError
CReferenceError
D30
Attempts:
2 left
💡 Hint
You cannot import default export using named import syntax.
Predict Output
advanced
2:00remaining
What is the output of this re-exporting code?
Given three files:
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);
AReferenceError
B7
Cundefined
DTypeError
Attempts:
2 left
💡 Hint
Re-exporting passes the export through another module.
Predict Output
expert
2:00remaining
What is the output of this dynamic import code?
Consider this code in 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();
AReferenceError
Bundefined
CSyntaxError
D42
Attempts:
2 left
💡 Hint
Dynamic import returns a promise resolving to the module object.