Skip to content

Commit 8ada20c

Browse files
declare 'cityOfBirth' before 'console.log' to in 2.js to fix ReferenceError
1 parent dc97183 commit 8ada20c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
33

4-
console.log(`I was born in ${cityOfBirth}`);
4+
// The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization
5+
// In JavaScript variables declared with 'const' or 'let' cannot be accessed before they are declared or initialized
6+
7+
8+
//SOLUTION
9+
// move the variable declaration above the 'console.log()'
510
const cityOfBirth = "Bolton";
11+
12+
console.log(`I was born in ${cityOfBirth}`);

0 commit comments

Comments
 (0)