JavaScript - const,let and var Quiz

Topics: JavaScript const, let, and var

JavaScript - const,let and var

4 mins read

1. What is the scope of a variable declared with `var`?

2. Which variable/constant declaration is hoisted to the top of its scope during the compilation phase?

3. What is the initial value of a `let` (before declaration)?

4. What is the output of the following code snippet?

const x = 10;

if (true) {
const x = 20;

5. Which of the below cannot be re-declared in the same scope?

6. What happens if you try to access a `const` before its declaration?

7. Which variable declaration is recommended for most use cases in modern JavaScript?

8. What is the difference between `var` and `let` in terms of hoisting?