Property Getter



Write a code to illustrate the use of getter method in JavaScript.

<html>
  <head>
    <title>Property Getter</title>
      <script>

        var car ={
            color: "Red",
            brand: "Ford",
            get company()
            {
                return this.brand;
            }
        };
        // Display data from the data getter:
        document.write("Company =" + car.company);
        
      </script>
    </head>
  <body>       
</body>
</html>

Output:

Company =Ford