One minute
JavaScript Objects
What is an Object In JavaScript?
An Object
is a JavaScript data type
which can be a collection of single or multiple key-value
pairs.
Let us take a look at this with some sample examples:
The example below shows a simple single key-value pair object:
const singleKeyValuePairObject = {
'name': 'John Doe'
};
Here’s another example of multiple key-value pairs object:
const multipleKeyValuePairsObject = {
'title': 'Mr',
'name': 'John Doe'
'age': 20,
'occupation': 'Software Engineer'
};
An object can also be nested
which means that we can have an object inside another object like so:
const multipleKeyValuePairsNestedObject = {
'title': 'Mr',
'name': 'John Doe'
'age': 20,
'occupation': 'Software Engineer',
'descriptions': {
'height': '193cm',
'weight': '85kg',
'complexion': 'dark',
'physique': 'muscular'
}
};