Skip to content

Commit 3b87801

Browse files
committed
mandatory-errors 2 is completed
1 parent e32fceb commit 3b87801

File tree

1 file changed

+18
-0
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+18
-0
lines changed

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

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

3+
4+
35
const age = 33;
46
age = age + 1;
7+
console.log(age);
8+
/*the constant variable cannot be reassigned a new value
9+
so in lin 6 we will get an error because it can not reassign the age variable with a new value of age + 1 which in this case is 34
10+
here is the error message we will get:/home/cyf/CYF/ITP/Module-Structuring-and-Testing-Data/Sprint-1/2-mandatory-errors/1.js:6
11+
age = age + 1;
12+
^
13+
14+
TypeError: Assignment to constant variable.
15+
16+
to fix this error we can use let instead of const because let variable can be reassigned a new value*/
17+
18+
let age2 = 33;
19+
age2 = age2 + 1;
20+
console.log(age2);
21+
22+
// now it will work fine and the output will be 34 and every time we run the code it will increase by 1

0 commit comments

Comments
 (0)