Skip to content

Commit b786029

Browse files
committed
fixed error order
1 parent 895a754 commit b786029

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

  • Sprint-2/2-mandatory-errors

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

Lines changed: 12 additions & 0 deletions
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+
error
5+
46
console.log(`I was born in ${cityOfBirth}`);
57
const cityOfBirth = "Bolton";
8+
9+
The reason there is an error is because we are using the wrong order, we are telling Javascript to print the value of cityOfBirth before creating a variable.
10+
So we need to create the variable first, this is because Javascript runs code from top to bottom, so a variable that is declared with const needs to be declared before using it.
11+
12+
13+
14+
right way
15+
16+
const cityOfBirth = "Bolton";
17+
console.log (`I was born in ${cityOfBirth}`);

0 commit comments

Comments
 (0)