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?

  1. var defines a variable while let defines a constant
  2. var defined function scoped variable while let define block scoped variable
  3. The value of a variable declared with var can be changed while the value of a variable declared with let cannot be changed
  4. 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.

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.