-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
13 lines (13 loc) · 595 Bytes
/
Copy path2.js
File metadata and controls
13 lines (13 loc) · 595 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
// Currently trying to print the string "I was born in Bolton" but it isn't working...
// what's the error ?
// ReferenceError: Cannot access 'cityOfBirth' before initialization
/*
console.log(`I was born in ${cityOfBirth}`);
let cityOfBirth = "Bolton";
*/
// The error is because cityOfBirth is declared with const and is being accessed before its declaration.
// Changing const to let to help solve the problem.
// I am also declaring the variable 'cityOfBirth' before before using it.
const cityOfBirth = "Bolton";
console.log(`I was born in ${cityOfBirth}`);
// Output: I was born in Bolton