Home >Web Front-end >Front-end Q&A >What are object properties in javascript

What are object properties in javascript

WBOY
WBOYOriginal
2022-04-11 14:12:502639browse

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"]”.

What are object properties in javascript

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What are object properties in JavaScript

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:

What are object properties in javascript

##[Related recommendations:

javascript video tutorialwebfrontend

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What does es6 come from?Next article:What does es6 come from?