Home >Web Front-end >Front-end Q&A >What are object properties in javascript
In JavaScript, the properties of an object refer to the values related to the object. An object is a collection of unordered properties. Properties can usually be modified, added and deleted. The syntax for accessing object properties is "objectName.property ” or “objectName["property"]”.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Properties are the most important part of any JavaScript object.
Properties refer to values associated with JavaScript objects.
JavaScript objects are collections of unordered properties.
Properties can generally be modified, added, and deleted, but some properties are read-only.
Access JavaScript properties
The syntax for accessing object properties is:
objectName.property // person.age
or:
objectName["property"] // person["age"]
or:
objectName[expression] // x = "age"; person[x]
The expression must Evaluated as a property name.
The example is as follows:
<!DOCTYPE html> <html> <body> <h1>JavaScript 对象属性</h1> <p>访问对象属性有两种不同的方法:</p> <p>您可以使用 .property 或 ["property"]。</p> <p id="demo"></p> <script> var person = { firstname:"Bill", lastname:"Gates", age:62, eyecolor:"blue" }; document.getElementById("demo").innerHTML = person.firstname + " is " + person.age + " years old."; </script> </body> </html>
Output result:
##[Related recommendations:javascript video tutorial 、webfrontend】
The above is the detailed content of What are object properties in javascript. For more information, please follow other related articles on the PHP Chinese website!