Re:Flatten Arrays in Vanilla JavaScript with Flat() and Flat...
by eyelidlessness on Wednesday January 05, 2022 @11:45PM
(#29819506)
I realize I could be clearer in what I’m asking for: please use const when you use reference types as values, and use let when you intend to mutate the reference. Using const and then changing a value is certainly allowed but it’s confusing and it’s missing an opportunity to signal in the code where changes might happen.
Re:Flatten Arrays in Vanilla JavaScript with Flat() and Flat...
by eyelidlessness on Wednesday January 05, 2022 @11:40PM
(#29819470)
I `readonly` and `as const` everything I possibly can. I do know that const doesn’t mean immutable, as I said, but I think it should and I think there’s value in establishing the idiom even if it’s not currently adopted. Because otherwise const basically means nothing unless you’re mutating everything already.
Anyway, I use TypeScript, so if I really want to assert that my array is immutable (as immutable as stuff in JS-land gets anyway) I just write:
or even