Home »
MCQs »
JavaScript MCQs
What is the main difference between var and let keywords in JavaScript?
21. What is the main difference between var and let keywords in JavaScript?
- var defines a variable while let defines a constant
- var defined function scoped variable while let define block scoped variable
- The value of a variable declared with var can be changed while the value of a variable declared with let cannot be changed
- All of the above
Answer: B) var defined function scoped variable while let define block scoped variable
Explanation:
The var and let keywords are both used for variable declaration in JavaScript. But, the main difference between them is that var defines function scoped variable while let defines block-scoped variable.