0 day streak
javascript / beginner
Snippet

Declaring Variables with const and let

In modern JavaScript, we use 'const' for values that won't change and 'let' for values that will be reassigned. This helps prevent bugs by making your intent clear.

snippet.js
javascript
1
2
3
4
5
const siteName = 'CapyPad';
let visitorCount = 0;
visitorCount = 10; // Allowed
// siteName = 'NewName'; // Error!
nextjs
Breakdown
1
const siteName = 'CapyPad';
Creates a constant variable that cannot be reassigned later.
2
let visitorCount = 0;
Creates a variable that can be changed as needed.