Is it possible to simulate constants in Javascript using closures?
问题 Is it possible to simulate constants in Javascript using closures? If so, can you please furnish me with an example? 回答1: Firefox and Chrome both support the const keyword. IE does not. So if you need constants and don't need to support IE, const isn't a bad choice. Keep in mind though, neither browser produces a runtime error when a value is assigned to a const ; the values merely remains unchanged. Otherwise, you must use functions to define constants that cannot be modified: function PI()