DEV Community

Randy Rivera
Randy Rivera

Posted on

Create a Basic JavaScript Object

  • Think about things people see every day, like cars, shops, and birds. These are all objects: tangible things people can observe and interact with.

  • What are some qualities of these objects? A car has wheels. Shops sell items. Birds have wings. These qualities, or properties, define what makes up an object. Note that similar objects share the same properties, but may have different values for those properties. For example, all cars have wheels, but not all cars have the same number of wheels.

  • Here's an example using these concepts to create a dog object:

let dog = {
  name: "Anakin",
  numLegs: 4
};
Enter fullscreen mode Exit fullscreen mode
  • This dog object has two property/value pairs: a name of Anakin and a numLegs of 4.

Top comments (0)