
I'm in favor of the latter, because it's more apparent how to specify a default value even if you don't want to increment by a certain amount (just make it a 1). If negative amounts are allowed, should there still be a DECREMENT operation?Īs function, the signature with support for both aforementioned options could look like INCREMENT(attr, default, amount) or INCREMENT(attr, amount, default). amount: add amount to current (or default) value.Corner cases: should it also initialize if the attribute exists already, but has a null value? Should INCREMENT not do anything or raise an error if the target attribute exists already and is non-numeric (e.g. default value: if target attribute doesn't exist, initialize with given default value.INCREMENT would be a lot more useful with the following two optional parameters: Note the change of INCREMENT from function to keyword to make the instruction shorter, but also less flexible.

😄ĮDIT: Another more direct proof that const outside strict mode uses function scope rather than block scope: Let's keep the issue focussed on its original topic: atomic key-value commands, not JS syntax. If any of you want to discuss this further I would suggest taking it to the mailing list or IRC. return arrays) rather than like the Map or Set equivalents (which is okay: they're also functions on the Object constructor like Object.keys rather than methods like the Map and Set equivalents). The additional functions Object.values and Object.entries are currently in stage 3 and will likely land in ES2016 or ES2017 but they will behave like Object.keys (i.e. Because Object.keys preceded the new collection types it will continue to return an array instead of a generator (and arrays can be treated as generators, i.e. And maps provide three generators: keys, values and entries (pairs of keys and values). The reason Object.keys is required is that objects aren't dictionaries. It's mostly about signalling intent: this variable will not be reassigned throughout this block of code.

log ( typeof x ) let x = 5 // throws some people have argued that it could be optimized but even if it were the difference would likely be insignificant. log ( typeof c ) const c = 5 // logs "undefined" console. log ( typeof v ) var v = 5 // logs "undefined" console. log ( typeof x ) let x = 5 // throws ReferenceError console. log ( typeof c ) const c = 5 // throws ReferenceError 'use strict' console. log ( typeof v ) var v = 5 // logs "undefined" 'use strict' console. execute each line individually in a fresh node shell // to avoid raising a TypeError when re-declaring const 'use strict' console.
