Object.freeze() JavaScript

The JavaScript Object freeze() method prevents existing properties from being modified and the new properties from being added on the specific object.

Syntax:

Object.freeze(object)

Parameters: object: It represents the object on which new properties are to be added or modified.

Return: Given object.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
const obj = { prop: 56 };
const obj2 = Object.freeze(obj);
obj2.prop = 65;
document.write(obj2.prop);
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com