Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Objects Deep Dive : Creating Objects With Object Literals

Monday, November 8, 2021

JavaScript Objects Deep Dive : Creating Objects With Object Literals

The most common ways you see how objects are created in JavaScript is the object literal syntax.  The object literal syntax is the open { } with comma separated name: pair value lists.  The name: part is the name of the property.  The part after : is the property value which can hold a primitive value or another object.  It could even be a function.

Here is an example of an object literal:

var product = {
    name: "Chai",
    Category: "Tea",
    Country: "India",
    supplier: {
        name: "ACME Tea Of India",
        location : "New Delhi"
    },
    related: ["Earl Grey", "Green Tea", "Dark Tea", "White Tea"],
    display: function () {
        console.log(this);
    }
};



If you open this in the browser you will see that product object is made up of properties, another object called supplier, an array related, and a function called display()

























3 comments:

  1. Thanks for your post. I’ve been thinking about writing a very comparable post over the last couple of weeks, I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks. https://www.whocall.biz

    ReplyDelete
  2. Define an object using { } brackets and key:values and their correlates differ by a comma. Depending upon the specific circumstances, it would either be a bare word which would be the name of the property or a literal or a function. I am also confuse in javascript program But recently I buy dissertation service in program which is very nice if you are stuck.

    ReplyDelete
  3. 22F76771D1
    Exploring new online resources can greatly enhance your learning experience, especially when you find reliable platforms. One such website is https://dtfhub.com/, which offers a variety of tools and tutorials to help users develop their skills. By utilizing this platform, you can access valuable content that supports your educational journey. It’s a great starting point for anyone looking to expand their knowledge base in a convenient and straightforward way.

    ReplyDelete