Esc6 object part 1
ES6 Objects
JavaScript variables can be Object data types that contain many values called properties.
An object can also have properties that are function definitions called methods for performing actions on the object.
ES6 introduces shorthand notations and computed property names that make declaring and using objects easier to understand.
The new method definition shorthand does not require the colon (:) or function keyword, as in the grow function of the tree objectdeclaration:
You can also use a property value shorthand when initializing properties with a variable by the same name.
For example, properties height and health are being initialized with variables named height and health:
When creating an object by using duplicate property names, the last property will overwrite the prior ones of the same name.
For Example:
Duplicate property names generated a SyntaxError in ES5 when using strict mode. However, ES6 removed this limitation.
Comments
Post a Comment