What is the difference between let and var in JavaScript?
a)
let
is block-scoped, while var
is function-scopedb)
var
is block-scoped, while let
is function-scopedc)
let
can be redeclared, while var
cannotd) There is no difference
Answer:
a)
let
is block-scoped, while var
is function-scopedExplanation:
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.