Skip to content
Advertisements

Object.isFrozen()

Why Object.isFrozen ?

Object.isFrozen () is used to control whether an object is frozen. (An object is frozen by Object.freeze ()) Returns a boolean value that is true or incorrect. If the “True” value is returned, the existing properties and values ​​in the object cannot be changed or new features added. If “False” returns, the property can be added or removed.

Syntax:

Object.isFrozen( obj )

obj: The object to be checked.

Return Value:

true if all of the following are true:

  • The object is non-extensible, which indicates that new properties cannot be added to the object.
  • The configurable attribute is false for all existing properties.
  • The writable attribute is false for all existing data properties.
  • If the object has no existing properties, the function returns true if the object is non-extensible.

Remarks

When the configurable property of an object property is incorrect, the properties cannot be changed and the feature cannot be removed. When the property of an object can be configured, the property property value cannot be changed.


JavaScript Object.isFrozen Examples

Example 1


        let animals = {
            dog: "dog",
            cat: "cat",
            bird: "bird"
        }

        let arr1 = Object.isFrozen(animals)
        console.log(arr1)

        Object.freeze(animals);
        let arr2 = Object.isFrozen(animals);
        console.log(arr2)

output:

false
true


Example 2

        let person = {
            hi: "hi guys..."
        };

        console.log(Object.isFrozen(person))

        Object.freeze(person)
        console.log(Object.isFrozen(person))

output:

false
true


Example 3


        let people = {
            person1: "alex",
            person2: "maria",
            person3: "rick"
        }

        people.person4 = "oliver";
        let arr1 = Object.isFrozen(people);
        console.log("object.isFrozen: " + arr1);
        console.log(people);

        Object.freeze(people);
        people.person5 = "barry";
        let arr2 = Object.isFrozen(people);
        console.log("object.isFrozen: " + arr2);
        console.log(people);

output:

object.isFrozen: false
{person1: “alex”, person2: “maria”, person3: “rick”, person4: “oliver”}

object.isFrozen: true
{person1: “alex”, person2: “maria”, person3: “rick”, person4: “oliver”}


Sources


Browser Support

Chrome6
Edgeyes
Firefox4
Internet Explorer9
Opera12
Safari5.1
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

1 Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: