0
0
Javascriptprogramming~5 mins

Global scope in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is global scope in JavaScript?
Global scope means a variable or function is accessible from anywhere in the code, no matter where it is used.
Click to reveal answer
beginner
Where are variables declared outside any function or block stored?
They are stored in the global scope and can be accessed anywhere in the program.
Click to reveal answer
intermediate
What happens if you declare a variable without let, const, or var inside a function?
It becomes a global variable, which can cause bugs because it is accessible everywhere.
Click to reveal answer
beginner
How can you avoid polluting the global scope?
Use let, const, or var inside functions or blocks to keep variables local.
Click to reveal answer
intermediate
What is the global object in browsers and how is it related to global scope?
In browsers, the global object is window. Variables in global scope become properties of window.
Click to reveal answer
Where can you access a variable declared in the global scope?
AOnly inside the block where it was declared
BOnly inside the function where it was declared
CAnywhere in the code
DNowhere, it is private
What happens if you forget to use let, const, or var when declaring a variable inside a function?
AIt becomes a global variable
BIt causes a syntax error
CIt becomes a block-scoped variable
DIt is deleted immediately
Which object represents the global scope in a browser environment?
Anavigator
Bdocument
Cconsole
Dwindow
How can you keep variables from polluting the global scope?
ADeclare them inside functions or blocks using <code>let</code> or <code>const</code>
BDeclare them without any keyword
CDeclare them only at the top of the file
DUse global variables everywhere
Which of these is true about global scope?
AGlobal scope variables are private to functions
BVariables in global scope can be accessed anywhere
CGlobal scope variables disappear after a function ends
DGlobal scope only exists inside blocks
Explain what global scope means in JavaScript and why it can be risky to use too many global variables.
Think about how variables can be seen everywhere and how that might cause problems.
You got /4 concepts.
    Describe how to avoid polluting the global scope when writing JavaScript code.
    Focus on how to keep variables limited to where they are needed.
    You got /4 concepts.