Last active
June 7, 2023 15:59
-
-
Save ernestlv/35784b5910320f8669e48de787da274d to your computer and use it in GitHub Desktop.
Defines a constant property in an object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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