diff --git a/1-js/02-first-steps/02-structure/article.md b/1-js/02-first-steps/02-structure/article.md index a8472ed4..a5903ce9 100644 --- a/1-js/02-first-steps/02-structure/article.md +++ b/1-js/02-first-steps/02-structure/article.md @@ -58,29 +58,29 @@ If you're curious to see a concrete example of such an error, check this code ou ```js run alert("Hello"); -["World"].forEach(alert); +[1, 2].forEach(alert); ``` -No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `World`. +No need to think about the meaning of the brackets `[]` and `forEach` yet. We'll study them later. For now, just remember the result of running the code: it shows `Hello`, then `1`, then `2`. Now let's remove the semicolon after the `alert`: ```js run no-beautify alert("Hello") -["World"].forEach(alert); +[1, 2].forEach(alert); ``` The difference compared to the code above is only one character: the semicolon at the end of the first line is gone. -If we run this code, only the first `Hello` shows. There are no numbers any more. +If we run this code, only the first `Hello` shows (and then you may see the error, but it may also be hidden). There are no numbers any more. The difference is because JavaScript does not assume a semicolon before square brackets `[...]`. And, as there's no semicolon, the code in the first example is treated as a single statement. Here's how the engine sees it: ```js run no-beautify -alert("Hello")["World"].forEach(alert) +alert("Hello")[1, 2].forEach(alert) ``` Looks weird, right? Such merging in this case is just wrong. We need to put a semicolon after `alert` for the code to work correctly.