javascript / beginner
Snippet
Declaring Variables with let and const
In modern JavaScript, 'const' is used for values that stay the same, while 'let' is used for variables that will change later. Using 'const' by default is a best practice to prevent accidental reassignments.
snippet.js
1
2
3
const birthYear = 1990;let currentAge = 34;currentAge = 35;
Breakdown
1
const birthYear = 1990;
Creates a constant variable that cannot be reassigned.
2
let currentAge = 34;
Creates a flexible variable that allows its value to be updated.
3
currentAge = 35;
Updates the value of the 'currentAge' variable.