7554425D-0054-440D-B95E-D2ABC13D62CD Created with sketchtool.
{body}
Your Saved Info Packages

View your saved Course or Program Packages containing pricing and detailed curriculum.

Speak with a Learning Advisor.

Have any questions? We'll call you.

Fill out the form below and a Learning Advisor will reach out at a time convenient for you.

Please pick a valid date and time between 9 AM and 8 PM eastern (Monday to Friday)

By clicking "Book a call," you accept our Terms and will also receive exclusive offers and updates about new courses, workshops and events.

JavaScript Tutorial

JavaScript Object

Ready to start your career in Development? Find out more about BrainStation's Web Development Bootcamp

Everything in JavaScript is an Object. You might hear this all the time while programming in JavaScript because all the types we use in JavaScript and all the programming language features in JavaScript are built around Objects. You can say it is the grand parent of all you use in JavaScript.

Objects put simply are just a collection of key-value pairs to define a real world entity in our code. Let’s take an example of building a web application for an educational organization where entities in the application would be students, teachers, grades for the students, courses, etc. Objects allows us a very efficient way to describe these entities in code by defining a collection of key-value pairs.

An object in JavaScript is defined by using a pair of curly brackets {} inside of which we define key-value pairs of the form key: value separated by comma ,.

Let’s build a student object that has first name, last name, age, course enrolled in, ID, status to indicate if the student has already graduated and the year and month in which the student got enrolled. The key uniquely identifies each of these unique features of a student and the value is the actual value stored in that key which is usually one of the primitive data types in JavaScript.

```
const student = {
	firstName: ‘John’,
	lastName: ‘Doe’,
	age: 29,
	course: ‘Intro to JavaScript’,
	ID: ‘woxku-jlsod-xmpiosd’,
	hasGraduated: false,
	year: 2022,
	month: ‘February’
}
```

Now that we have a student object, let’s try to access and change the values using the key value pairs defined above within the student object. There are two main ways of accessing values from an object - Dot Notation (using a period .) and Bracket Notation (using a pair of square brackets [])

Dot Notation

When using dot notation to access values from an object, you specify the name of the object followed by the dot and followed by the key that you are interested in accessing the value for.

```
const student = {
	firstName: ‘John’,
	lastName: ‘Doe’,
	age: 29,
	course: ‘Intro to JavaScript’,
	ID: ‘woxku-jlsod-xmpiosd’,
	hasGraduated: false,
	year: 2022,
	month: ‘February’
}

// using dot notation, access course for this student
console.log(student.course); // prints ‘Intro to JavaScript’

// using dot notation, check if the student has graduated
console.log(student.hasGraduated); // prints false
```

Bracket Notation

Sometimes the key in an object to be accessed is not known beforehand. In this case, bracket notation comes handy. In the example below, we store the key to be accessed in a variable and when the key to be accessed is known, we use the bracket notation to access the value stored in that key. Remember the key used inside of bracket notation has to be in single quotes.

```
let keyToAccess = null;

const student = {
	firstName: ‘John’,
	lastName: ‘Doe’,
	age: 29,
	course: ‘Intro to JavaScript’,
	ID: ‘woxku-jlsod-xmpiosd’,
	hasGraduated: false,
	year: 2022,
	month: ‘February’
}

// later in the code, we know the key to access.
keyToAccess = ‘ID’

// using bracket notation, access ID for this student by using
// keyToAccess variable
console.log(student[keyToAccess]); // prints ‘woxku-jlsod-xmpiosd’

// using bracket notation, access firstName and lastName
console.log(student[‘firstName’]); // prints ‘John’
console.log(student[lastName]); // prints ‘Doe’
```
Set Password

You already have an account with BrainStation, but you still need to set up a password.