Skip to content

Commit 895a754

Browse files
committed
using 'let' to reassign the value
1 parent 57efea5 commit 895a754

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
// trying to create an age variable and then reassign the value by 1
2-
3-
const age = 33;
2+
let age= 33;
43
age = age + 1;
4+
5+
console.log (age);
6+
7+
8+
9+
const means that the variable age is a constant and cannot be reassigned. When we try to reassign the value of age by adding 1 to it, we get an error.
10+
This is because we cannot change the value of a constant variable once we have created it.
11+
12+
If we want to change the value of age, we need to use let instead of consts when declaring the variable. this then allows us to reassign the value of age by adding 1 to it.
13+
14+
15+

0 commit comments

Comments
 (0)