Hacker News new | ask | show | jobs
by denton-scratch 1866 days ago
Let is syntactic sugar.

To me, the code smell is the syntax from BASIC (and later C) that goes:

<code> x = y </code>

I've always disliked that notation; it looks like the statement "the value of x is the same as the value of y". So "let" turns the code into something that makes sense when read aloud.

I don't think syntactic sugar is a code smell.

2 comments

Syntactic sugar is syntax that makes it easier ("sweeter") to do something the language can already do. For example, async/await is syntactic sugar for promises.

let isn't syntactic sugar — it's the only way to declare a reassignable block-scoped variable (as opposed to const, which can't be reassigned, and var, which is function-scoped or globally-scoped).

The way to redefine a const is to define an object who's values are mutable. I strongly prefer that as I can couple the mutating behavior in a single object.
Thanks. I was thinking in BASIC, I guess.
The core problem with the BASIC syntax isn't the lack of a keyword, it's that stupid = sign. Assignment almost kind of means equals, except it actually totally doesn't, which is the absolute worst kind of resemblance. Oh, and now you also have to invent some other construct like == for actual equality!

I'm admittedly not sure what symbol should be used instead. I'd suggest <= except it reads as "less than or equal to".