Skip to content

Commit 1915855

Browse files
committed
fixing the error by declaring and initializing the var before accessing it
1 parent d9ef102 commit 1915855

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
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+
//const cityOfBirth = "Bolton";
7+
8+
/* When we try to run our code it is giving us an error saying ReferenceError: Cannot access 'cityOfBirth' before initialization
9+
and this is because we tried to access the var cityOfBirth before we declared and initialized it*/
10+
11+
// We can overcome this error by declaring and initializing the var cityOfBirth before accessing it

0 commit comments

Comments
 (0)