Must-know Javascript object property security

sefatanam

Sefat Anam

Posted on April 23, 2023

Must-know Javascript object property security

Do you know about writable, configurable & configurable these property descriptor in JavaScript ?

The age property in this code serves to store the age of a Member object. By defining the age property with writable, configurable, and enumerable flags set to false, the code is essentially creating a read-only property that cannot be changed or deleted once it has been set. This helps ensure that the age property remains accurate and consistent throughout the lifetime of the Member object, and that it cannot be accidentally or maliciously modified or deleted.

If an attempt is made to modify the age property, as shown in the example code with anam.age=24, the operation will fail silently and the age property will retain its original value. Similarly, attempts to delete the age property with delete anam.age will also fail silently, and the property will continue to exist on the object.

Javascript object property security, you must know!

💖 💪 🙅 🚩
sefatanam
Sefat Anam

Posted on April 23, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related