0
0
Javascriptprogramming~20 mins

Importing values in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Import 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 import?
Given the following module mathUtils.js exporting a constant, what will be logged by main.js?
Javascript
/* mathUtils.js */
export const pi = 3.14;

/* main.js */
import { pi } from './mathUtils.js';
console.log(pi);
Anull
Bundefined
CReferenceError
D3.14
Attempts:
2 left
💡 Hint
Remember that named exports can be imported with curly braces.
Predict Output
intermediate
2:00remaining
What happens if you import a non-exported value?
Consider this module data.js and the import in app.js:
Javascript
/* data.js */
const secret = 'hidden';
export const visible = 'shown';

/* app.js */
import { secret } from './data.js';
console.log(secret);
ASyntaxError
Bundefined
CTypeError
Dhidden
Attempts:
2 left
💡 Hint
Only exported values can be imported.
Predict Output
advanced
2:00remaining
What is the output when importing a default export?
Look at these two files:
Javascript
/* greet.js */
export default function greet() {
  return 'Hello!';
}

/* index.js */
import greet from './greet.js';
console.log(greet());
Aundefined
BHello!
CTypeError
DSyntaxError
Attempts:
2 left
💡 Hint
Default exports are imported without curly braces.
Predict Output
advanced
2:00remaining
What error occurs when mixing default and named imports incorrectly?
Given this module and import:
Javascript
/* utils.js */
export default function() { return 'default'; }
export const named = 'named';

/* app.js */
import { default as def, named } from './utils.js';
console.log(def(), named);
AReferenceError
BTypeError
Cdefault named
DSyntaxError
Attempts:
2 left
💡 Hint
You can rename default import using named import syntax.
🧠 Conceptual
expert
2:00remaining
Which option correctly imports all exports as an object?
You want to import everything from module.js as a single object named mod. Which import statement is correct?
Aimport * as mod from './module.js';
Bimport mod from './module.js';
Cimport { * as mod } from './module.js';
Dimport { mod } from './module.js';
Attempts:
2 left
💡 Hint
Use the star (*) syntax to import all exports as an object.