Skip to content

Commit 934aeec

Browse files
place cityOfBirth variable and assigned value ahead of console log statement to fix error
1 parent c0c20fc commit 934aeec

File tree

1 file changed

+10
-1
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
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}`);
54
const cityOfBirth = "Bolton";
5+
console.log(`I was born in ${cityOfBirth}`);
6+
7+
//ReferenceError: Cannot access 'cityOfBirth' before initialization
8+
9+
// This is happening because we are trying to use the variable cityOfBirth
10+
// before it has been declared and assigned a value.
11+
12+
// Variables declared with let and const can't be accessed before they are initialized.
13+
14+
// To fix this error, we need to declare and assign a value to cityOfBirth before we try to log it to the console.

0 commit comments

Comments
 (0)