You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/1-key-errors/1.js
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,35 @@
2
2
3
3
// Why will an error occur when this program runs?
4
4
// =============> write your prediction here
5
+
// I predict that this program will throw a error - due to the variable decimalNumber being redeclared.
5
6
6
7
// Try playing computer with the example to work out what is going on
7
8
8
-
functionconvertToPercentage(decimalNumber){
9
+
/* function convertToPercentage(decimalNumber) {
9
10
const decimalNumber = 0.5;
10
11
const percentage = `${decimalNumber * 100}%`;
11
12
12
13
return percentage;
13
14
}
14
15
15
-
console.log(decimalNumber);
16
+
console.log(decimalNumber); */
16
17
17
18
// =============> write your explanation here
19
+
// Function covertToPercentage(decimalNumber) - it has a parameter named decimalNumber
20
+
// Inside the function: const decimalNumber =0.5; - this redeclares the same variable name that's already used for the parameter.
21
+
// That causes an error: SyntaxError: Identifier 'decimalNumber' has already been declared - because you can't declare a const (or let) with the same name as a parameter inside the same function scope.
22
+
// JavaScript doesn't allow us to declare a new variable with the same name in the same scope, so it caused an error.
0 commit comments