7 ms·
I feel the same towards the article, I think that the moment you need to resort to "think of it as..." it's the moment you lose me. I also don't think he does
by epolanski 4y ago
I feel the same towards the article, I think that the moment you need to resort to "think of it as..." it's the moment you lose me.
I also don't think he does a good job at explaining the biggest source of misunderstanding. Quoting the article:
`Expressions and statements are distinct things.`
That is not really correct.
A function call, e.g. is both an expression and a statement:
`foo(bar)` on it's own is both an expression (it returns a value, even if the value returned is undefined) and a statement.
In fact, determining if a piece of code is an expression or a statement in all borderline cases depends on the context.
```
const foo = function bar(){};
function bar(){}
```
On line 1 the bar function is an expression, on bar 3, is a statement.
There's nothing really about the function on it's own that can tell you whether it is an expression or a statement.
On the other hand, a nice way to differentiate statements from expressions is that you cannot use statements where you need expressions.
```
console.log(if (3 > 2) {})
const foo = while (i < 3) {}
```
both lines are syntax errors.
- azangru 4y agoI've never read the ECMAScript spec; but searching through it, I can see that the terms they use is function declaration vs function expression. According to their terminology, function bar(){} on the second line of your function example is a function declaration.
- epolanski 4y agoYes, and a function declaration is a statement.