Skip to content

Instantly share code, notes, and snippets.

@Kishimoto96
Forked from halitbatur/discussion.md
Created March 18, 2023 09:33
Show Gist options
  • Save Kishimoto96/23a36288eda0e766eb85456dd393d242 to your computer and use it in GitHub Desktop.
Save Kishimoto96/23a36288eda0e766eb85456dd393d242 to your computer and use it in GitHub Desktop.
Object discussion questions

Object Discussion Questions

There is some coding in this discussion. Feel free to write them in a REPL or in the comments below.

  1. How is an object different from an array?
  2. How does const work with objects?
  3. Explain the difference between bracket syntax and dot syntax. Give an example of something that works with bracket syntax but not dot syntax. Give an example of something that works with dot syntax but not bracket syntax.
  4. What are computed properties? Write an example code.
  5. What is the difference between Object.keys and Object.entries? Write example code using both of them.
  6. How do we get only the values of an object?
@nourkrimesh
Copy link

// M.NOUR Krimesh, Abdul Malek, Ammar Almuain.

  1. The difference between object and array is that object store its data as key:value and arrays store the data as indexed values.

  2. const prevent us from defining another variable with the same name but we can change object's values.

  3. Bracket notation allows you to access properties with special characters in their names, while you can not do this with dot notation

  4. Computed properties allow you to dynamically choose what property in your object gets updated.

  5. Object.keys(object) is a utility function that returns the list of keys of object for example:
    const hero = {
    name: 'Batman',
    city: 'Gotham'
    };
    Object.keys(hero); // => ['name', 'city']

    Object.entries(object) is an useful function to access the entries of object for example:
    const hero = {
    name: 'Batman',
    city: 'Gotham'
    };
    Object.entries(hero); // => [['name', 'Batman'], ['city', 'Gotham']]

  6. We get only the values of an object by using Object.values(object) for example:
    const books = {
    'book1': 5.50,
    'book2': 10.00,
    'book3': 4.35
    };
    const prices = Object.values(books);
    prices; // => [4.35, 5.5, 10]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment