Using constants as indices for JavaScript associative arrays

In ECMAScript 6 you can use computed values for object keys: var CONSTANT_A = 0, CONSTANT_B = 1 var state_machine = { [CONSTANT_A]: function () { return ‘a’ }, [CONSTANT_B]: function () { return ‘b’ } }; console.log(state_machine) This does not work in Internet Explorer 11 nor in Safari browsers: https://kangax.github.io/compat-table/es6/#test-object_literal_extensions_computed_properties

Should I use std::string or const char* for string constants? [duplicate]

Usually you should prefer std::string over plain char pointers. Here, however, the char pointer initialized with the string literal has a significant benefit. There are two initializations for static data. The one is called static initialization, and the other is called dynamic initialization. For those objects that are initialized with constant expressions and that are …

Read more

Does using const on function parameters have any effect? Why does it not affect the function signature?

const is pointless when the argument is passed by value since you will not be modifying the caller’s object. Wrong. It’s about self-documenting your code and your assumptions. If your code has many people working on it and your functions are non-trivial then you should mark const any and everything that you can. When writing …

Read more