Skip to content

Instantly share code, notes, and snippets.

@blainsmith
Created August 26, 2013 19:45
Show Gist options
  • Save blainsmith/6345780 to your computer and use it in GitHub Desktop.
Save blainsmith/6345780 to your computer and use it in GitHub Desktop.
JavaScript Constant Variables with Object.freeze();
var CONST = {
API_KEY: '123456789abcdefg',
PI: 3.14
};
Object.freeze(CONST);
// Will print {API_KEY: "123456789abcdefg", PI: 3.14}
console.log(CONST);
// Attempt to change the value of PI to something else, but won't happen
CONST.PI = 2.2399;
// Attempt to add a new key to to the object
CONST.NEW_CONST = 'test';
// Will print the same {API_KEY: "123456789abcdefg", PI: 3.14}
console.log(CONST);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment