Complete the code to declare a variable that can be hoisted.
console.log([1]); var [1] = 5;
let or const which are not hoisted in the same way.Using var declares a variable that is hoisted, so x is hoisted but undefined before assignment.
Complete the code to fix the hoisting issue with function declarations.
[1] greet() { console.log('Hello!'); } greet();
var or let which do not hoist the function body.function keyword.Function declarations are hoisted entirely, so function keyword is needed.
Fix the error in the code by choosing the correct keyword to avoid temporal dead zone.
console.log(x); [1] x = 10;
let or const, which cause TDZ ReferenceError.function, which is invalid syntax here.Using var hoists the declaration (initialized to undefined), avoiding the TDZ error that occurs with let or const.
Fill in the blank to create a block-scoped variable and avoid hoisting issues.
{ [1] x = 20; console.log(x); } console.log(x);var inside the block, which hoists and leaks the variable outside.function keyword incorrectly.Using let (or const) inside the block scopes x to that block only. The outside console.log(x) throws ReferenceError, avoiding the hoisting pitfall of var leaking the variable outward (which would log 20 then undefined).
Fill all three blanks to correctly declare and use variables avoiding hoisting pitfalls.
console.log([1]); [2] [3] = 15;
let which causes temporal dead zone error.Using var y hoists the declaration but not the initialization, so console.log(y) prints undefined.