Skip to content

Instantly share code, notes, and snippets.

@AkashRajvanshi
Created November 2, 2019 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkashRajvanshi/46028cfa83bb8e0cca0e3a67f9794f3d to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/46028cfa83bb8e0cca0e3a67f9794f3d to your computer and use it in GitHub Desktop.
const user = {
firstName: 'Akash'
}
// Sealing Object
Object.seal(user)
console.log(Object.isSealed(user)) // true
// Configurable == false ( we can't add or delete properties )
const descriptor = Object.getOwnPropertyDescriptor(user, 'firstName')
console.log(descriptor.configurable) // false
console.log(Object.isExtensible(user)) // false
user.lastName = 'Rajvanshi'
console.log('lastName' in user) // false
delete user.firstName
console.log('firstName' in user) // true
// Only we can do is write existing properties
user.firstName = 'Abha';
console.log(user.firstName) // Abha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment