0
0
Javascriptprogramming~10 mins

Why modules are used in Javascript - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to export a function named greet.

Javascript
export function [1]() { console.log('Hello!'); }
Drag options to blanks, or click blank then click option'
Ahello
Bgreet
CsayHello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'greet'.
2fill in blank
medium

Complete the code to import the greet function from 'greetings.js'.

Javascript
import { [1] } from './greetings.js';
Drag options to blanks, or click blank then click option'
AsayHello
Bhello
Cwelcome
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Importing a function name that was not exported.
3fill in blank
hard

Fix the error in the code to correctly export a constant named PI.

Javascript
const PI = 3.14;
[1] PI;
Drag options to blanks, or click blank then click option'
Aexport
Bexports
Cexport default
Dmodule.exports
Attempts:
3 left
💡 Hint
Common Mistakes
Using CommonJS export syntax in ES modules.
4fill in blank
hard

Fill both blanks to create a module that exports a function and imports another.

Javascript
import { [1] } from './math.js';

export function [2]() {
  return [1](5, 3);
}
Drag options to blanks, or click blank then click option'
Aadd
Bsubtract
Cmultiply
Ddivide
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up function names for import and export.
5fill in blank
hard

Fill all three blanks to create a module exporting a default function and importing named ones.

Javascript
import { [1], [2] } from './utils.js';

export default function [3]() {
  [1]();
  [2]();
}
Drag options to blanks, or click blank then click option'
AlogInfo
BlogError
ChandleLogs
DprocessData
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing default export with named imports.