Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

const #13

Open
nelsonic opened this issue Sep 13, 2016 · 0 comments
Open

const #13

nelsonic opened this issue Sep 13, 2016 · 0 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Sep 13, 2016

const the most missused / missunderstod feature of ES6...?

The MDN description is:

Constants are block-scoped, much like variables defined using the let statement.
The value of a constant _cannot change through re-assignment, and it _can't be redeclared.
see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const

In light of that definition, Does this look right to you?

latest-safari-const-behaviour

(the way Latest Safari handles const .)
naah

Should you be relying on const to write error free code when its behaviour is inconsistent across "Modern Browsers"...?

But I can still use const in my Node.js Code because V8 has "consistent" behaviour, right...?
Why are you writing Node.js (JavaScript) code in the first place?
Is it because JS is a "better" programming language (for servers) than Go or Rust? (hint it isn't!)
Or because Node.js offers us the chance to write One Language Everywhere...? (and thus only have to learn one thing to be productive on a development team ...)
Writing "full-stack" or "universal" (what used be called "isomorphic") JS is the whole point of using Node.js in the first place. So if you're going to write code for the server that cannot run in browsers without "transpilation", you are totally defeating the objective and might as well be using "Rails".

If we have to keep context-switching between server and client code (i.e. remember when we can/can't use const) we're losing the benefit of writing code that "_Works Everywhere_TM" ... why not type fewer characters (i.e. var) and just write better (fewer lines of) code where it's obvious if someone is trying to re-assign or re-define a variable that should not be changed? we even have a convention for values that should not be altered: var CONFIG = 'don't change this' a declaration in ALLCAPS is one you shouldn't modify. see: http://nodeguide.com/style.html#constants i.e. it's obvious to your team members what your intention is and you can still write 100% portable code.

At the time-of-writing const has good support in most browsers (on the surface)
http://caniuse.com/#feat=const suggests that 96% of browsers (in use) support the feature.
caniuse-const-browsers

Depending on your target audience you may need to still be supporting Internet Explorer 10 ... 😞
in which case you will need to "transpile" const to var ... unless you are already using a "transpiler" in your project, it can be quite "expensive" to download/adopt one: dwyl/learn-closure-compiler#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant