What are objects?
Objects are data that contain key-value pairs.
We store our key-value pairs within curly braces. If we want to store more than one key-value pairs, we have to separate each one of them with a comma.
We may think of the objects in Javascript like the objects in the real life, for example the oven and his characteristics:
Object values
Objects may store primitive and object value, therefore every valid value for the JavaScript language.
Getting the value of a property
We may get the value of a property (Key) in two ways:
through object name + a period (".") + property or through object name + square brackets ("[plus "property "]").
There is two circumstances where we have to use square brackets:
first, when the property is a value of a variable:
second, when the property name is an invalid identifier that
respect this rules:
. when it is not one word
. when it starts with a number
. when it is a reserved keyword
. when it doesn`t consist only of numbers, letters or underscores.
Setting the value of a property
We may set the value of a property with the name of our object followed by a dot and then our value.
Or, name of our object followed by square brackets inside double quotes then our value.
Deleting properties
Functions are object in javaScript
Functions are a special kind of object in JavaScript:
- we may assign a property to a function like an object
- we may assign a function like a value of a property. A function that becomes a value of a property is called method and as a normal function we may put inside arguments. We may call our method with dot or square brackets
Top comments (1)
Thanks