Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Type of "properties of object" in JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 121
    Comment on it

    In this tutorial we will learn about the properties of an object in JavaScript, classification of the properties, attributes of properties.There are 3 kinds of properties an object in JavaScript have:


    1: Data Property: In this property of javascript object the data is represented by the key: value pairs.

    For Example: object abc has a data property whose name is the string "prop1" and whose value is the number 456.

        var abc = {
            prop1: 456
        };
    

    This property has following attributes

    value : (It's the properties value) writable : (It can be set as true or false) enumerable : (It can be set as true or false, so that the property show in a loop constructs) configurable : (It can be set as true or false, so that the property can be deleted)


    2: Accessor Property: This property is of 2 types

    2.1- getter property: Using the getter property we can dynamically change the values by calling the function implicitly.This property has the following attributes.

    a. enumerable
    b. configurable
    c. get

    2.2- setter property: Using the setter property we pass a value as an argument and the setter function returns a value.The call made here is also implicitly.This property has the following attributes.

    a. enumerable
    b. configurable
    c. set


    Note: writable and value Attribute does not exist for getter and setter properties.

    Example of getter & setter property:

    <script>
            var obj = {
    
           get_prop() {
                document.write("get_prop function is called implicitly");
            },
    
           set_prop(value) {
                document.write("set_prop function is called implicitly and passes a value as an argument: "+value);
            }
        }
    
        obj.get_prop();     
        obj.set_prop(562);
    
        </script>
    

    Output for get_prop: get_prop function is called implicitly
    Output for set_prop: set_prop function is called implicitly and passes a value as an argument: 562


    3: Internal Property: These properties are represented by double square brackets

    For Example: one of the internal properties is [[Extensible]]
    

    [[Extensible]] : This internal property determines can we add more properties to an object or not. We can read it using Object.isExtensible() and set it false using Object.preventExtensions().

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: