4 ms·
No intent to sound negative, but doesn’t explanation by numerous cues mud the water even more? I bet most of students are left confused with this “wrapper state
by wruza 4y ago
No intent to sound negative, but doesn’t explanation by numerous cues mud the water even more? I bet most of students are left confused with this “wrapper statement” thing. Magical thinking induced.
If the question is how they are different, then the answer is grammatically, and then the explanation of a grammar follows.
If it is why we make such distinction, then the answer is because the language creator decided so, followed by tradeoffs and pitfalls of making a specific language construct to have a value.
- epolanski 4y agoI 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.