Hacker News new | past | comments | ask | show | jobs | submit login

> const is called immutable which is misleading

Consider that this may simply be a knowledge gap on your end. I think most programmers understand the concept of value vs reference types and would not assume an object to be a value type. Obviously the reference is immutable, as is any other value type you assign to the const.

> nor the implicit return of last block statement are mentioned

Probably not mentioned because it doesn’t exist. There is no implicit return of the last block statement. That statement is misleading in at least two ways: there cannot be multiple top-level block statements as the body of a function, nor does the singular block statement body of an arrow function implicitly return the last expression. It actually requires an explicit return statement. On the other hand, an arrow function with an expression body -does- implicitly return.




>Consider that this may simply be a knowledge gap on your end.

My experience says this is very far from the truth. JavaScript's implementation of const is confusing for almost everyone the first time they come across it, especially the area you're talking about - changing collections. Junior engineers and non JavaScript senior engineers alike don't seem to understand what const actually means until they dig in to get deeper context, which I would point as a pretty big failure of language design.


I think it's a failure of education, specifically around the concept of binding as the general case of assignment.

I came late to that myself, not encountering it as a discrete concept until I got interested in Lisp, and found it clarified a great deal for me that had previously been obscure.

With that concept available, const is trivially explained as an immutable binding, as indeed the author of the book under discussion explains it elsewhere in this comment thread.

Without it, yeah, const feels full of special cases, just like everything else involving non-primitive types. It's something I've learned to cover early in teaching the language, because a little early effort there goes a long way toward clearing up a lot of confusion later.


I don't think it is really confusing if you already know how "final" works in Java or (const) references in C++.


Good point. However, most web developers starting with JS tend to come from PHP with its &$variable reference-passing magic.

I seem to have chosen my wording badly, since I did not mean (labeled) blocks, but indeed the expression body (which may have been referenced in the book as a ”block”, too lazy to check).


Maybe they meant implicit return after the last block statement (ie the implicit return void)? But that's not exclusive to arrow functions, so probably not.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: