ECMAScript 5 introduced new Object methods to Javascript. Among them preventExtensions , seal , freeze methods will be compared to each other.

preventExtensions

An object called by this method can't have any new properties being added.

Example

let person = { name : "Agustin" , age : 27 , } ; Object . preventExtensions ( person ) ; Object . isExtensible ( person ) ; person . surname = "Ramirez" ; console . log ( person . surname ) ; person . name = "Maria" ; console . log ( person ) ; delete person . age ; console . log ( person ) ;

seal

An object called by this method can not have any new properties being added or current properties deleted.

Example

let person = { name : "Agustin" , age : 27 , } ; Object . seal ( person ) ; Object . isSealed ( person ) ; person . foo = "something" ; console . log ( person . foo ) ; person . name = "Maria" ; console . log ( person ) ; delete person . age ; console . log ( person ) ; Object . defineProperty ( person , "name" , { get : ( ) => "Juan" , } ) ; console . log ( person ) ;

freeze

An object called by this method can not have any further changes done to it.

Example

let person = { name : "Agustin" , age : 27 , } ; Object . freeze ( person ) ; Object . isFrozen ( person ) ; person . name = "Maria" ; console . log ( person ) ;

shallow only

All of these methods only work on object properties shallowly, meaning that just work with the direct property references.

let person = { name : "Agustin" , age : 27 , address : { country : "Argentina" , city : "Corrientes" , } , } ;

Feature matrix