What is the difference between let and var in JavaScript?

What is the difference between let and var in JavaScript?

a) let is block-scoped, while var is function-scoped
b) var is block-scoped, while let is function-scoped
c) let can be redeclared, while var cannot
d) There is no difference

Answer:

a) let is block-scoped, while var is function-scoped

Explanation:

The key difference between let and var is their scope. let is block-scoped, meaning it is only accessible within the block where it is declared, while var is function-scoped, meaning it is accessible throughout the function where it is declared.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top