4 ms·
What I like about JS is I can write nearly everything with const. Functions are const, data is const, and I rarely use classes. It removes a lot of overhead, a
by bern4444 5y ago
What I like about JS is I can write nearly everything with const.
Functions are const, data is const, and I rarely use classes. It removes a lot of overhead, avoids this questions, and makes everything consistent and so makes spotting similarities and differences easier.
I can do
const myFunc = () => 2;
const res = myFunc();
It helps with the mindset of treating functions as data that can be acted upon similar to how data can be.
- ironmagma 5y agoYes, but it’s with the caveat that (like C++) const does not mean that the whole value is constant. It doesn’t even really mean any part of the value is constant necessarily, just that the symbol cannot be reassigned. I don’t know that it eliminates that many questions, but it does eliminate one question, which is whether that variable will be reassigned. Arguably that doesn’t tell you very much.
- bern4444 5y agoIts more for style true, but I also try to avoid directly modifying an object's properties and values.