1. Scope
Define block scoped
A block scoped variable means that the variable defined within a block will NOT be accessible from outside the block. A block can reside inside a function, and a block scoped variable will not be available outside the block even if the block is inside a function.
Matching When our JavaScript code is run in the browser, the JavaScript engine actually makes two separate passes over our code: compilation and execution. Match each of these concepts with the correct description. ___ Compilation Phase ___ Execution Phase A. Allocates memory, sets up.... B. Runs out code line-by-line....
A. Compilation Phase - Allocates memory, sets up.... B. Execution Phase - Runs out code line-by-line.....
True or False Given this JavaScript code: --------------------------------- function oneAndOne() { const num1 = 1; const num2 = 2; const num1 + num2; } oneAndOne(); console.log(num1); ------------------------------- The console.log method on the last line will log the number 1.
False
Are variables created with var block scoped?
No, they are NOT block scoped.
True or False All variables and functions declared in outer scopes are available in inner scopes via the scope chain.
True
True or False Closure gives you access to an outer function's variables from an inner function.
True
True or False Every function creates its own scope, and any variables or function you declare inside of the functions will not be available outside of it.
True
True or False Lexical scope in JavaScript means that a variable defined outside a function can be accessible inside the function, but not the other way around.
True
True or False Variables created without a const, let, or var keyword are ALWAYS globally scoped?
True
Are variables declared with 'const' and 'let' block-scoped?
Yes, they are block-scoped.
Which of the following variables are globally scoped? ----------------------------------- let var1 = 1; function firstFunc(var2 = 2) { let var3 = 3; return var1 = var2; }
var1
What variables does 'outerFunc' have access to? -------------------------------------- const var1 = 1; function outerFunc(var2 = 2) { const var3 = 2; function innerFunc() { const var4 = 4; } return var1 + var2; }
var1, var2, var3
What variables does 'innerFunc' have access to? --------------------------------------- const var1 = 1; function outerFunc(var2 = 2) { const var3 = 2; function innerFunc() { const var4 = 4; } return var1 + var2; }
var1, var2, var3, var4