Skip to content

Commit 9584255

Browse files
committed
updated to correct code error
1 parent 81e5bf5 commit 9584255

File tree

1 file changed

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

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
3+
// ReferenceError: Cannot access 'cityOfBirth' before initialization
4+
/*
45
console.log(`I was born in ${cityOfBirth}`);
6+
let cityOfBirth = "Bolton";
7+
*/
8+
// The error is because cityOfBirth is declared with const and is being accessed before its declaration.
9+
// Changing const to let to help solve the problem.
10+
// I am also declaring the variable 'cityOfBirth' before before using it.
511
const cityOfBirth = "Bolton";
12+
console.log(`I was born in ${cityOfBirth}`);
13+
// Output: I was born in Bolton

0 commit comments

Comments
 (0)