Home > Article > Web Front-end > Detailed explanation of examples of using JavaScript objects and attribute operations_Basic knowledge
All variables in JavaScript are objects, with two exceptions: null and undefined.
A common misconception is that number literals are not objects. This is due to a bug in the JavaScript parser, which attempts to parse dot operators as part of a floating-point literal value.
There are many workarounds to make number literals look like objects.
Object as data type
JavaScript objects can be used as hash tables, mainly used to save the corresponding relationship between named keys and values.
A simple object can be created using the object literal syntax - {} -. This newly created object inherits from Object.prototype and does not have any custom properties.
Access properties
There are two ways to access the properties of an object, the dot operator or the bracket operator.
Translator’s Note: In the JSLint syntax detection tool, the dot operator is a recommended practice.
Delete attributes
The only way to delete a property is to use the delete operator; setting a property to undefined or null does not actually delete the property, but only removes the association between the property and the value.
Syntax of attribute names
The attribute name of an object can be declared using strings or ordinary characters. However, due to another incorrect design of the JavaScript parser, the second declaration method above will throw a SyntaxError before ECMAScript 5.
The reason for this error is that delete is a keyword in the JavaScript language; therefore, in order to run normally under lower versions of JavaScript engines, string literal declaration must be used.