Skip to content

Commit 6c20163

Browse files
committed
fix: resolve variable initialization order error
1 parent 0420930 commit 6c20163

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • Sprint-1/2-mandatory-errors

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33

44
console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
// ERROR: Cannot access 'cityOfBirth' before initialization console.log(`I was born in ${cityOfBirth}`); // ERROR: Cannot access 'cityOfBirth' before initialization
8+
// Fixed: Swapped the line order to resolve the ReferenceError.
9+
10+
11+
const cityOfBirth = "Bolton";
12+
console.log(`I was born in ${cityOfBirth}`); // SUCCESS: Variable is initialized first

0 commit comments

Comments
 (0)