JavascriptEasy
Language View:
What is the difference between var, let, and const?
Answer (English)
English Answer
In JavaScript, var, let, and const are used to declare variables. var is the older method and has function scope; it allows both redeclaration and reassignment. let has block scope and allows reassignment but not redeclaration in the same scope. const also has block scope, but its value cannot be reassigned after it is declared. In modern JavaScript, let and const are preferred over var.
var | let | const |
|---|---|---|
Function Scoped | Block Scoped | Block Scoped |
Can be redeclared | Cannot | Cannot |
Can be updated | Can | Cannot |
difference
More from
Discussion0
Please sign in to leave a comment.
