Skip to content

Commit dc97183

Browse files
change age variable declaration from 'const' to 'let' to allow reassignment and explained the error it causes when attempted
1 parent 814abb5 commit dc97183

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

‎Sprint-2/2-mandatory-errors/1.js‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
// trying to create an age variable and then reassign the value by 1
22

3-
const age = 33;
3+
// The problem here is that 'const' creates a constant variable which cannot be reassigned, attempting to reassign (age = age + 1) throws a TypeError: Assignment to constant variable.
4+
5+
6+
//change 'const' to 'let' so the value can be updated
7+
// const age = 33;
8+
let age = 33;
49
age = age + 1;
10+
11+
// console.log(age);

0 commit comments

Comments
 (0)