Difference between freeze and seal

I just heard about the JavaScript methods freeze and seal, which can be used to make any Object immutable.

Here’s a short example how to use it:

var o1 = {}, o2 = {};
Object.freeze(o2);

o1["a"] = "worked";
o2["a"] = "worked";

alert(o1["a"]);   //prints "worked"
alert(o2["a"]);   //prints "undefined"

What is the difference between freeze and seal? Can they increase performance?

9 Answers
9

Leave a Comment