javascript / beginner
Snippet
Variables with const and let
In modern JavaScript, we use 'const' for values that won't change and 'let' for variables that will be reassigned. This helps prevent accidental bugs.
snippet.js
1
2
3
4
const greeting = 'Hello World';let counter = 0;counter = counter + 1;console.log(greeting, counter);
nodejs
Breakdown
1
const greeting = 'Hello World';
Declares a constant variable that cannot be reassigned.
2
let counter = 0;
Declares a variable that can be changed later.