Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a variable with block scope using let.
Javascript
let [1] = 5; console.log(x);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'var' instead of a variable name.
Using 'const' as a variable name.
Using an undeclared variable name.
β Incorrect
The variable x is declared using let, which has block scope and is hoisted but not initialized.
2fill in blank
mediumComplete the code to declare a constant variable.
Javascript
const [1] = 10; console.log(value);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using 'var' or 'let' instead of 'const'.
Using a different variable name than in the console.log.
β Incorrect
The constant variable value is declared with const and cannot be reassigned.
3fill in blank
hardFix the error in accessing a let variable before declaration.
Javascript
console.log([1]); let a = 3;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using a variable name not declared.
Trying to access the variable before declaration.
β Incorrect
Accessing a before its declaration causes a ReferenceError due to the temporal dead zone of let.
4fill in blank
hardFill both blanks to create a block-scoped variable and log it.
Javascript
{
[1] x = 7;
console.log([2]);
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using
var which is function-scoped.Logging a variable name not declared.
β Incorrect
Using let declares a block-scoped variable x, which can be logged inside the block.
5fill in blank
hardFill all three blanks to declare a constant and log its value.
Javascript
const [1] = 20; function show() { console.log([2]); } show(); console.log([3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
π‘ Hint
Common Mistakes
Using different variable names in the blanks.
Using a variable not declared.
β Incorrect
The constant PI is declared and logged inside and outside the function.