0
0
Javascriptprogramming~10 mins

Common hoisting pitfalls in Javascript - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable that can be hoisted.

Javascript
console.log([1]); var [1] = 5;
Drag options to blanks, or click blank then click option'
Ax
Blet
Cy
Dconst
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using let or const which are not hoisted in the same way.
Using a variable name not declared.
2fill in blank
medium

Complete the code to fix the hoisting issue with function declarations.

Javascript
[1] greet() { console.log('Hello!'); } greet();
Drag options to blanks, or click blank then click option'
Avar
Bfunction
Clet
Dconst
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using var or let which do not hoist the function body.
Omitting the function keyword.
3fill in blank
hard

Fix the error in the code by choosing the correct keyword to avoid temporal dead zone.

Javascript
console.log(x); [1] x = 10;
Drag options to blanks, or click blank then click option'
Avar
Bconst
Clet
Dfunction
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using let or const, which cause TDZ ReferenceError.
Using function, which is invalid syntax here.
4fill in blank
hard

Fill in the blank to create a block-scoped variable and avoid hoisting issues.

Javascript
{ [1] x = 20; console.log(x); } console.log(x);
Drag options to blanks, or click blank then click option'
Afunction
Bvar
Clet
Dconst
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using var inside the block, which hoists and leaks the variable outside.
Using function keyword incorrectly.
5fill in blank
hard

Fill all three blanks to correctly declare and use variables avoiding hoisting pitfalls.

Javascript
console.log([1]); [2] [3] = 15;
Drag options to blanks, or click blank then click option'
Ay
Bvar
Dlet
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using let which causes temporal dead zone error.
Mismatching variable names.