Object.freeze() JavaScript

The JavaScript Object freeze() method prevents existing properties from being modified and it also prevents the new properties to be 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>

Output:

56
Please Share