Redeclaration
- Declaration means creating a variable
- Redeclaration means re-creating a variable
_7var x1 = 10;_7let x2 = 20;_7const x3 = 30;_7_7var x1 = 80; // - ✅ Allowed_7let x2 = 70; // - ❌ Error_7const x3 = 90; // - ❌ Error
Reassignment
Changing the value of the variable
_7var x1 = 10;_7let x2 = 20;_7const x3 = 30;_7_7x1 = 180; // - ✅ Allowed_7x2 = 170; // - ✅ Allowed_7x3 = 190; // - ❌ Error
const - exception
- Our exceptation might be wrong about
const
since we must embrace howJS
works - We object/array is declaraed with
const
inside value could be modified
_20const player = {_20 name: "Gukesh D",_20 game: "chess",_20 age: 16,_20 rating: 2699,_20 title: "Grandmaster",_20};_20_20player.rating = 2710; // - ✅ Allowed_20console.log(player);_20// Output_20{_20 name: "Gukesh D",_20 game: "chess",_20 age: 16,_20 rating: 2710,_20 title: "Grandmaster",_20};_20_20player = 10; // - ❌ Error
_7const movies = ["Vikram", "KGF", "RRR", "Valimai"];_7movies[1] = "Master"; // - ✅ Allowed_7_7console.log(movies);_7// Output_7// ["Vikram", "Master", "RRR", "Valimai"]_7movies = "cool"; // - ❌ Error
@ragavkumarv
swipe to next ➡️