Home > Article > Web Front-end > How javascript objects are defined
First of all, an object is also a variable, but an object can contain multiple variables. Objects are containers for variables.
Use the var keyword to define objects.
JavaScript uses a {...} to represent an object, and the key-value pair is declared in the form xxx: xxx, separated by,.
Example:
var 对象名字={ 属性 方法 <script> var xiaoming={ name:"worker", age:23, salary:7000, }; alert(worker.salary+worker.name+worker.age); </script> };
Summary
1. Remember the semicolon after the curly braces;
2. Separate each attribute with a comma.
Recommended tutorial: js introductory tutorial
The above is the detailed content of How javascript objects are defined. For more information, please follow other related articles on the PHP Chinese website!