JavaScript Enhanced Object Literals
Learn about enhanced object literals in JavaScript.
By the end of this lesson, we’ll be able to do the following:
- Use the object literal shorthand for initializing property values.
- Use the object literal shorthand for writing methods.
- Create objects with dynamically computed property keys.
Enhanced object literals
ES6 offers enhanced object literals, including shorthand syntax for method definition, property values, and dynamic property keys.
Shorthand for initializing property values
ES6 checks if the property key has a corresponding variable name and assigns the value of that variable to the property. If no variable has the same name as the property key defined, an error will be thrown.
Get hands-on with 1200+ tech skills courses.