Data structures — Objects

Coccagerman
2 min readAug 20, 2021

In JavaScript, an object is a collection of key-value pairs, similar to a map, dictionary, or hash-table in other programming languages.

  • An Object is a collection of properties and methods.
  • A Property is a key-value pair that contains a name and a value.
  • A Property Name is a unique value that can be coerced to a string that points to a value.
  • A Property Value can be any value, including other objects.
  • Methods are functions that are declared within the object and later on can only be called through this object.

In javascript objects come with many built-in methods that allow us to perform different operations and get information from a given object.

Objects are a good way to group together data that have something in common or are somehow related. Also, thanks to the fact that property names are unique, objects come in handy when we have to separate data based on an unique condition.

In javascript objects are declared within braces and each key-value pair is separated by a comma. Each key-value pair is built with a property name, a colon and the property value or method.

let obj = {
name: 'german',
ladrar: function() {console.log('guau!')}
}

For accessing values we just call the object name followed by a point and the property name.

obj.name

If we want to execute a method, we do the same but followed by parenthesis.

obj.ladrar()

--

--