Giter Club home page Giter Club logo

flw1-u2l6-23-24-student-exercises's Introduction

Lesson 2.6: Objects

Introduction

In this lesson, you will learn about JavaScript objects. Objects are data structures in JavaScript that allow you to store and organize data in a more meaningful way. You'll use objects to create, access, and update data efficiently.

Key Concepts

  • Objects are created using curly brackets {}.
  • Objects consist of property-value pairs.
  • Properties (keys) must be unique within an object.
  • Values can be of various data types.
  • Objects can contain arrays and other objects.

Code Example

let classroom = {
  name: "Computer Lab",
  numberOfSeats: 25,
  occupied: true,
  students: ["Emily", "Michael"]
};

Accessing Values

  • Dot notation (object.property) is used to access specific property values within an object.
  • Arrays within objects can also be accessed using dot notation or bracket notation.

Code Example

let character = {
  fullName: "Kirby",
  color: "pink",
  age: 10,
  mood: "cheerful",
  hobbies: ["eating", "sleeping"]
};

// Accessing property values
let characterName = character.fullName; // "Kirby"

// Accessing the first hobby in the array
let firstHobby = character.hobbies[0]; // "eating"

Updating Objects

  • Objects can be updated by accessing a property and assigning a new value using the assignment operator (=).
  • New properties can be added to objects in a similar way.

Code Example

let user = {
  instaTag: "badbunnypr",
  firstName: "Bad",
  lastName: "Bunny",
  followers: 56700000
};

// Updating the "followers" property
user.followers = 56700001;

// Adding a new property
user.numPosts = 15;

Happy coding! ๐Ÿ˜Š

flw1-u2l6-23-24-student-exercises's People

Contributors

cn-curriculum avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.