0
0
Javascriptprogramming~5 mins

Module scope in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is module scope in JavaScript?
Module scope means variables and functions declared inside a module are only accessible within that module, not outside it.
Click to reveal answer
beginner
How do you create a module in JavaScript?
You create a module by saving code in a separate file and using import and export statements to share parts of it.
Click to reveal answer
beginner
What happens if you declare a variable inside a module without exporting it?
That variable stays private to the module and cannot be accessed from other modules.
Click to reveal answer
beginner
Why is module scope useful?
It helps keep code organized and avoids name conflicts by hiding variables and functions inside modules.
Click to reveal answer
beginner
How do you export a function from a module?
Use <code>export function myFunc() {}</code> or <code>export { myFunc }</code> to make it available outside the module.
Click to reveal answer
What does module scope restrict?
AAccess to variables and functions outside the module
BAccess to global variables
CAccess to browser APIs
DAccess to CSS styles
Which keyword is used to share code from a module?
Aimport
Bexport
Cvar
Dlet
If a variable is not exported, can other modules use it?
AOnly if declared with var
BYes, always
CNo, it stays private
DOnly if imported
How do you import a function named foo from a module?
Avar foo = require('./module.js');
Bexport foo from './module.js';
Clet foo = import('./module.js');
Dimport foo from './module.js';
What is a benefit of module scope?
AIt hides variables to avoid conflicts
BIt slows down code
CIt disables functions
DIt makes all variables global
Explain what module scope is and why it is important in JavaScript.
Think about how modules keep code separate and private.
You got /4 concepts.
    Describe how you share and use code between JavaScript modules.
    Focus on how to make code available outside a module.
    You got /4 concepts.