Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Last active June 7, 2023 15:59
Show Gist options
  • Save ernestlv/35784b5910320f8669e48de787da274d to your computer and use it in GitHub Desktop.
Save ernestlv/35784b5910320f8669e48de787da274d to your computer and use it in GitHub Desktop.
Defines a constant property in an object.
const obj = {};
Object.defineProperty(obj, "x", { value: 42, writable: false });
// or
const obj2 = {
get x() {
return 42;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment