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
// The function when called was supposed to capitalise the first letter of a string by calling the first character of the string and then transforming
4
+
// to uppercase character and adding it back to the string, but because the variable "str" had already been declared it going to throw a syntaxerror
3
5
4
6
// call the function capitalise with a string input
5
7
// interpret the error message and figure out why an error is occurring
6
8
7
-
functioncapitalise(str){
8
-
letstr=`${str[0].toUpperCase()}${str.slice(1)}`;
9
-
returnstr;
10
-
}
11
-
9
+
// function capitalise(str) {
10
+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
11
+
// return str;
12
+
// }
13
+
// console.log(capitalise("what is your name?"))
12
14
// =============> write your explanation here
15
+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
16
+
// ^
17
+
18
+
// SyntaxError: Identifier 'str' has already been declared
19
+
// As predicted,when the function is called, it does not compile and throws a syntax error because the identifier "str" had already been declared as a parameter of the function. This violate the rules of JavaScript
20
+
// Variable can be re-assigned using the "let" keyword but cannot be redeclared
0 commit comments