As io.js now supports ES6 you are finally able to use the const
and let
keywords. Obviously, let
is the successor of var
, jus
I have the same feeling that you're describing. A big percentage of declared variables in my code tend to be constant, even objects and arrays. You can declare constant objects and arrays and still be able to modify them:
const arr = [];
arr.push(1);
arr;
// [ 1 ]
const obj = {};
obj.a = 1;
obj;
// { a: 1 }
AFAIK ES6 modules do not require variable declarations when importing, and I suspect that io.js will move to ES6 modules in a near future.
I think this is a personal choice. I'd always use const when requiring modules and for module local variables (foo
in your example). For the rest of variables, use const appropriately, but never go mad and use const everywhere. I don't know the performance between let and const so I cannot tell if it's better to use const whenever possible.