Posts

Showing posts with the label const

const in Javascript - ES6

Code for this and several other ES-6 features can be found in my  github "const" keyword in ES6 is used to declare immutable variables. This is not something new to ES6. It was completely possible to declare immutable variables in ES5. But it had to be done in a really verbose manner by using the  object.defineProperty  keyword and setting the writable  property to null as follows: Object.defineProperty(typeof global === "object" ? global : window,'immutable5',{ configurable: false, enumerable: false, writable: false, value:'I am immutable by ES5'}); However in ES-6 immutable variables can be defined in a simple manner as follows: const immutable6 = 'I am immutable by ES6';