JavaScript Part 2: let, const & Data Types

javascript dev.to

1. let — The Modern Variable let was introduced in ES6 (2015) and is now the preferred way to declare variables that can change their value. let age = 20; console.log(age); // 20 age = 21; // ✅ you can update it console.log(age); // 21 Why let over var? The key difference is scope — let is block-scoped, meaning it only exists within the {} block it was defined in. if (true) { let message = "Hi!"; console.log(message); // ✅ works here } console.log(message);

Read Full Tutorial open_in_new
arrow_back Back to Tutorials