javascript / beginner
Snippet
Variable Constants with Const and Let
Use 'const' for values that should never change after being set, and 'let' for variables that you need to update later. This helps prevent bugs by making your intent clear.
snippet.js
1
2
3
4
5
6
7
const API_URL = 'https://api.example.com';let loginAttempts = 0;export default function AuthStatus() {loginAttempts += 1;return <p>Target: {API_URL}</p>;}
nextjs
Breakdown
1
const API_URL = ...
Ensures the URL cannot be accidentally overwritten elsewhere in the script.
2
let loginAttempts = ...
Allows the value to be incremented or modified as the user interacts with the app.