Skip to content

Commit 24ee904

Browse files
committed
Fix variable initialization error by moving console.log after declaration in 2.js
1 parent 3b87801 commit 24ee904

File tree

1 file changed

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

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
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}`);
4+
//console.log(`I was born in ${cityOfBirth}`);
55
const cityOfBirth = "Bolton";
6+
7+
/*/home/cyf/CYF/ITP/Module-Structuring-and-Testing-Data/Sprint-1/2-mandatory-errors/2.js:4
8+
console.log(`I was born in ${cityOfBirth}`);
9+
^
10+
11+
ReferenceError: Cannot access 'cityOfBirth' before initialization
12+
13+
this error is because we are trying to access the variable cityOfBirth before it is initialized and assigned a value.
14+
the console.log should be after the variable declaration and assignment
15+
16+
*/
17+
console.log(`I was born in ${cityOfBirth}`);

0 commit comments

Comments
 (0)