0
0
Javascriptprogramming~10 mins

Module scope in Javascript - Interactive Code Practice

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

Complete the code to declare a variable inside a module scope.

Javascript
const [1] = 10;
console.log(value);
Drag options to blanks, or click blank then click option'
AvarValue
BmoduleVar
Cvalue
DglobalValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the one logged.
Using var which is function scoped, not module scoped.
2fill in blank
medium

Complete the code to export a function from a module.

Javascript
export default function [1]() {
  return 'Hello from module';
}
Drag options to blanks, or click blank then click option'
AsayHello
Bgreet
ChelloWorld
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is not descriptive.
Forgetting to export the function.
3fill in blank
hard

Fix the error in the code by completing the import statement correctly.

Javascript
import [1] from './module.js';
console.log(greet());
Drag options to blanks, or click blank then click option'
Agreet
BsayHello
Chello
Dwelcome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different name than the exported function.
Forgetting to import the function.
4fill in blank
hard

Fill both blanks to create a private variable and a public function accessing it.

Javascript
const [1] = 42;
export function getValue() {
  return [2];
}
Drag options to blanks, or click blank then click option'
AsecretNumber
BsecretValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names in the two blanks.
Trying to export the variable directly.
5fill in blank
hard

Fill all three blanks to export a constant, import it, and log its value.

Javascript
export const [1] = 3.14;

import { [2] } from './constants.js';

console.log([3]);
Drag options to blanks, or click blank then click option'
API
DE
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for export and import.
Logging a variable that was not imported.