Javascript

Javascript is a versatile programming language used for creating dynamic and interactive web content.

Advanced Topics

Objects and Arrays

Organizing Data: Objects

Objects are like backpacks for information! They let you store related things together.

let student = {
  name: "Jesse",
  age: 15,
  isEnrolled: true
};

You can get the name with student.name or check if they're enrolled with student.isEnrolled.

Lists of Data: Arrays

Arrays are lists of items, like a row of lockers.

let colors = ["red", "green", "blue"];

Access them by number (starting from 0): colors[1] is "green".

Why Use Objects and Arrays?

  • Objects keep related info together
  • Arrays help when you have lots of similar things

Combining Objects and Arrays

You can even put objects inside arrays, or arrays inside objects!

let students = [
  {name: "Jesse", age: 15},
  {name: "Morgan", age: 14}
];

Examples

  • Storing a list of players and their scores in a game

  • Keeping track of items in a shopping cart

In a Nutshell

Objects and arrays help you organize lots of information easily.

Key Terms

Object
A collection of values grouped together.
Array
An ordered list of values.