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 an object will be permanent and the object cannot be extensible again after applying prevention.

Syntax:

Object.preventExtensions(object)

Parameters:
object: It represents the object that has to be prevented 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>