0
0
Javascriptprogramming~20 mins

Variable declaration using const in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Const Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of const with object mutation
What is the output of the following code?
Javascript
const obj = { a: 1 };
obj.a = 2;
console.log(obj.a);
Aundefined
B1
CTypeError
D2
Attempts:
2 left
💡 Hint
Remember, const prevents reassignment but not mutation of object properties.
Predict Output
intermediate
2:00remaining
Output of const with primitive reassignment
What happens when you run this code?
Javascript
const x = 5;
x = 10;
console.log(x);
ATypeError
B10
C5
DReferenceError
Attempts:
2 left
💡 Hint
Can you change the value of a const variable?
🧠 Conceptual
advanced
2:00remaining
Why use const for arrays?
Which statement about const arrays is true?
AYou cannot add or remove elements from a const array.
BYou can change elements inside a const array but cannot reassign the array variable.
CYou can reassign a const array variable to a new array.
DConst arrays are immutable and cannot be changed in any way.
Attempts:
2 left
💡 Hint
Think about what const protects: the variable binding or the content.
Predict Output
advanced
2:00remaining
Output of const in block scope
What will this code print?
Javascript
const a = 1;
{
  const a = 2;
  console.log(a);
}
console.log(a);
A2 1
B2 2
C1 2
D1 1
Attempts:
2 left
💡 Hint
Remember const variables are block scoped.
Predict Output
expert
2:00remaining
Output of const with destructuring and reassignment
What is the output of this code?
Javascript
const [x, y] = [1, 2];
x = 3;
console.log(x, y);
A3 2
B1 2
CTypeError
DReferenceError
Attempts:
2 left
💡 Hint
Can you reassign a const variable after destructuring?