Complete the code to declare a variable using hoisting.
console.log([1]); var x = 5;
The variable x is hoisted, so it exists before its declaration but is undefined.
Complete the code to show hoisting with a function declaration.
[1] sayHello() { console.log('Hello!'); } sayHello();
var, let, or const instead of function.Function declarations are hoisted, so sayHello can be called before its definition.
Fix the error in the code to demonstrate hoisting with var.
console.log(a); [1] a = 10;
let or const which cause ReferenceError here.Using var hoists the variable declaration, so a exists but is undefined before assignment.
Fill both blanks to create a hoisted function expression and call it.
var greet = [1]() { console.log('Hi!'); }; greet[2]();
The function expression is assigned to greet and called with parentheses ().
Fill all three blanks to create a hoisted variable and function, then call the function.
console.log([1]); [2] greet() { console.log('Hello!'); } var [1] = 'Hello'; greet[3]();
var instead of variable name in first blank.The variable message is hoisted and undefined before assignment. The function greet is declared and called with parentheses.