Coding task · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects
Creating Objects
An object literal is written in braces as key: value pairs. You access a property with dinosaur.name or dinosaur['species'], and you add a new property with an assignment, e.g. dinosaur.enclosure = 'Zone A'.
Task
Create an object dinosaur with the properties name: 'Rexy', species: 'Tyrannosaurus Rex', age: 25 and isCarnivore: true, and with a nested object stats that has the property health: 95. After creating the object, add a property enclosure with the value 'Zone A'. Display name using dot notation and species using bracket notation in the console.