Skip to content

Commit 6697426

Browse files
committed
update: Fix variable declaration order and error explanation in sprint -1 of 2.js
1 parent fa0ebc7 commit 6697426

File tree

1 file changed

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

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Currently trying to print the string "I was born in Bolton" but it isn't working...
22
// what's the error ?
3-
4-
console.log(`I was born in ${cityOfBirth}`);
53
const cityOfBirth = "Bolton";
4+
console.log(`I was born in ${cityOfBirth}`);
5+
6+
//The error is that the variable cityOfBirth is being used before it has been declared.JavaScript executes code line by line from top to bottom, so you must declare and assign a value to the variable before using it.
7+
// In JavaScript, variables declared with let or const are not hoisted, meaning they cannot be accessed before their declaration.

0 commit comments

Comments
 (0)