Welcome back , In this lecture, we would briefly run through the fundamentals of JavaScript object, which is the single , most important feature of JavaScript language.

Imagine trying to access your data (stored variables) with their respective names and denotations, using an Array, you find out that it is not possible, simply because Arrays are index based and order restrictive. But thanks to Object for coming to our rescue as it does exact opposite i.e allows us to store our data using a key-value pair, meaning each value has a name which is called the key and to it is assigned a value.

In simple terms, we can use object to group together different variables that belong together and that have no particular order, one of the major difference between Array and Object .

Below are code snippet that better illustrates what we've been explaining all this while.

But before that , how do we initialize an Object in JavaScript??. we do so by simply assigning to a variable a name followed by the assignment operator (=) and then curly braces { } which houses our key value pairs .

It can be done in two ways, first the Object literals and second, using the New object syntax

// Object Literals
var Arsenal = {
     nickName: 'Gunners ๐Ÿ”ซ',
     Location: 'London ๐Ÿ‡ฌ๐Ÿ‡ง'
     manager: '๐ŸŽฉ๐Ÿ‡ช๐Ÿ‡ธArteta' ,
     homegrounds: 'Highbury,Emirates ๐ŸŸ๏ธ',
     outfield col: 'Red & white ๐Ÿ”ดโšช',
     wonUcl: false;
//Dot notation
 console.log(Arsenal) //whole entry
//Bracket notation
var ๐ŸŸ๏ธ = 'homegrounds' ;
console.log([๐ŸŸ๏ธ])// Highbury, Emirates ๐ŸŸ๏ธ

From the above code blocks it is obvious that there are two new inclusion which we haven't talked about and that is no other thing than Dot notation and **bracket notation.**

Very simple concept you know?? Both used while retrieving our stored data. Dot notation is used by calling the variable name linking the object and the key(property) of the key-value pair we intend to call.

Using the above snippet, we wanted to retrieve the data stored for Arsenal's manager and with that we called the var name i.e Arsenal linked to the property i.e manager with a dot(.) Notation


For the bracket notation, similar formality is followed just that the dot is replaced by a square bracket [ ] and the entry is accustomed by quotes to indicate string.

e.g Arsenal[ 'location' ] which will print 'London๐Ÿ‡ฌ๐Ÿ‡ง'.

And lastly let us talk about the second method of initializing an Object i.e New object syntax

var league = new object();
league.rank = 'top' ;
league.teams = 20;
league['tiers'] = 4;

console.log(league) // all object entries

This is similar to new array syntax where we created a new object and through the variable name (league) we kept updating the object, using both dot and bracket notations.

NB: object entries can also be mutated i.e changed/ updated same way it's done in arrays , variables and other data entry methods.