Skip to content

Commit b29e7e4

Browse files
Fix redeclaration error in 0.js
1 parent b2459ed commit b29e7e4

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

  • Sprint-3/1-key-errors

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
//I think this code will show a SyntaxError. The function has two variables named str in the same scope.
33
// ACTUAL ERROR (running the original code with `node 0.js`):
44
// C:\Users\EarthHarvestAdmin\CYF2026 LAMLA KAMANA\Module-JavaScript-Fundamentals\Sprint-3\1-key-errors\0.js:8
5-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
6-
^
7-
5+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
86
//SyntaxError: Identifier 'str' has already been declared
97

108
// WHY IT IS ILLEGAL (DEEPER EXPLANATION):
@@ -28,8 +26,8 @@
2826
// interpret the error message and figure out why an error is occurring
2927

3028
function capitalise(str) {
31-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
32-
return str;
29+
const result = `${str[0].toUpperCase()}${str.slice(1)}`;
30+
return result;
3331
}
3432
console.log(capitalise("hello"));
3533
// str is used both as the function parameter (function capitalise(str)) and again in let str = ...

0 commit comments

Comments
 (0)