Variables in Java Script
In JavaScript, variables act as containers for storing data values, which are categorized into various data types.
Three Ways to Declare Variables
Modern JavaScript uses
let and const, while var is an older keyword mostly avoided today.const(Constant): Use this for values that should not change once set.- Rule: You must assign a value when you declare it.
let: Use this for values that can be reassigned (changed) later.var: The original way to declare variables. It is generally avoided because it can be used before it’s declared (hoisting) and has less predictable scoping.