Object.preventExtensions() JavaScript

The Javascript Object preventExtensions() method prevents any extensions of an object i.e. no new property can be added and no existing property can be modified.

Note: Prevention on object will be permanent and object cannot be extensible again after applying prevention.

Syntax:

Object.preventExtensions(object) 

Parameters:
object: It represents the object that have to be prevent from any extensions.

Return:
Non extensible object.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
const a = {};  
Object.preventExtensions(a);  
a.alpha = 56;    
document.write(a.hasOwnProperty("alpha"));   
</script>
</body>
</html>

Output:

false
Please Share