Skip to content

Commit 21f66d6

Browse files
committed
declare variable before using it
1 parent 2e44be5 commit 21f66d6

File tree

1 file changed

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

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
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+
// The error is that cityOfBirth is used before it is declared.
8+
// In JavaScript, variables declared with const or let cannot be accessed before their declaration due to the temporal dead zone.
9+
// To fix the error, we need to declare and initialize cityOfBirth before using it in the console.log statement.
10+

0 commit comments

Comments
 (0)