TypeScript Variables and Constants Quiz
A 35-question TypeScript & JavaScript quiz covering variable declarations, scope rules, hoisting, reassignment behavior, constants, immutability concepts, shadowing, and best practices for naming variables.
Question 1
Which declaration creates a block-scoped variable?
Question 2
What is true about var declarations?
Question 3
What is the result?
let x = 5;
x = 10;
console.log(x);Question 4
Which declaration prevents reassignment?
Question 5
What happens here?
const count = 1;
count = 2;Question 6
What is hoisting?
Question 7
What prints?
console.log(a);
var a = 10;Question 8
What happens here?
console.log(b);
let b = 5;Question 9
Which scope type does var use?
Question 10
What logs?
{ let x = 1; }
console.log(typeof x);Question 11
What prints?
function test() {
var a = 10;
}
console.log(typeof a);Question 12
What is true about block scope?
Question 13
Which declarations allow redeclaration in the same scope?
Question 14
What happens?
let x = 1;
let x = 2;Question 15
What does const prevent?
Question 16
What logs?
const obj = { n: 1 };
obj.n = 2;
console.log(obj.n);Question 17
What is required to make an object fully immutable?
Question 18
What happens with shadowing here?
let x = 1;
{
let x = 2;
console.log(x);
}Question 19
Shadowing occurs when:
Question 20
What prints?
var a = 10;
(function(){ var a = 20; console.log(a); })();Question 21
Which naming style is recommended for variables?
Question 22
What makes a variable name good?
Question 23
Why should overly generic names be avoided?
Question 24
What logs?
console.log(x);
var x = 5;
console.log(x);Question 25
Which declaration helps avoid accidental global leakage?
Question 26
What happens if you assign a variable without declaring it?
Question 27
Which is true about const with primitive values?
Question 28
Why is var generally discouraged?
Question 29
What is the main benefit of using const whenever possible?
Question 30
What is the recommended default declaration for new variables?
Question 31
Which is a valid reason to choose let instead of const?
Question 32
What is the effect of block-scoped declarations in loops?
Question 33
Which variable naming pattern should be avoided?
Question 34
What prints?
let n = 1;
{
n = 2;
}
console.log(n);Question 35
Best practice suggests avoiding:
