File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
Sprint-1/2-mandatory-errors Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change 11// trying to create an age variable and then reassign the value by 1
22
3+
4+
35const age = 33 ;
46age = 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
You can’t perform that action at this time.
0 commit comments