Page 220 - Web_Application_v2.0_C12_Fb
P. 220

car2.model = "Superb";
                  car2.year = 2025;
                  // Displaying the car details using document.write()

                  document.write("Brand: " + car2.brand + "<BR>");
                  document.write("Model: " + car2.model + "<BR>");
                  document.write("Year: " + car2.year);
                  </SCRIPT>
                  </BODY>
                  </HTML>
              Output:

















              Accessing Properties

              You can access object properties in JavaScript using Dot Notation or Bracket Notation.
              The syntax to access a property using Dot Notation is as follows:

                  objectName.propertyName;
              For example:
                  const car = { brand: "Toyota", model: "Corolla" };

                  // Output: Corolla
                  document.write("Dot Notation Output: " + car.model);
              You can also use the object's name followed by square brackets ([]) with the property name in quotes.

              The syntax to access a property using Bracket Notation is as follows:

                  objectName["propertyName"];
              For example:

                  const car = { brand: "Toyota", model: "Corolla" };
                  // Output: Toyota
                  document.write("Bracket Notation Output: " + car["brand"]);
              Manage Object Properties

              Some properties to manage objects are as follows:
                Adding a Property: To add a new property, use dot (.) or bracket ([]) notation.

                 The syntax to add a property is as follows:
                 object.propertyName = value;

                 // OR
                 object["propertyName"] = value;
                218   Touchpad Web Applications (Ver. 2.0)-XII
   215   216   217   218   219   220   221   222   223   224   225