Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Forked from louisrli/discussion.md
Created April 29, 2021 16:54
Show Gist options
  • Save halitbatur/10774b50c5bcdce2ce5cf9d8d8c8e609 to your computer and use it in GitHub Desktop.
Save halitbatur/10774b50c5bcdce2ce5cf9d8d8c8e609 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?
@ghufran-adel
Copy link

ghofran .nouh . mohammed . yaman
0)the object has value & key ..so it can store more detailed data.. while array store the data as a list .

1)const in object give us the possibility to change the object content .

  1. the bracket notation allows us to access object properties using variable while dot not ,for example
    obj.123; // ❌ SyntaxError
    obj['123']; // ✅ 'digit'
    because it starts with a digits and every thing that works with dot notation dose work with bracket notation.

4)when we use( Object.keys) the return value is "string" but in case (Object.entries) the return value is array that consist of a key and a value.
Object.keys example:
const object1 = {
a: 'somestring',
b: 42,
c: false
};

console.log(Object.keys(object1));
object.entries example:
const object1 = {
a: 'somestring',
b: 42
};

for (const [key, value] of Object.entries(object1)) {
console.log(${key}: ${value});
}

// expected output:
// "a: somestring"
// "b: 42"

5)console.log(Object.values(object1));

@HasanAldhahi
Copy link

HasanAldhahi commented Apr 9, 2022

Group 10
Hasan, Rama, Mohammed, and Melek
1)
Array is different type of object where order matter and it has hidden properties like an object using dot operator like "summary and length"" you can access these hidden property. Object is the preferred way to store collection of data for CRUD Data operations.
The Const keyword makes a variable itself immutable, not its assigned content meaning that Object's properties including keys and values can be changed but the data structure type of that declared Const variable can't be changed to other types.

The main difference between bracket and dot notation is that bracket notation allows us to access object properties using variables. To access JavaScript object properties using bracket notation, the key should be. Property identifiers have to be a String or a variable that references a String. Property identifiers cannot start with a number.
For the Arrays the method to access the elements is using the bracket syntax. array[0] the JavaScript engine takes the number 0 change it into string and access the element automatically where u cannot use dot operator.
For Objects, the preferred method to access the values of the keys is using the dot operator JavaScript ES5 (2015) new edition added more features such as .? for accessing objects and checking if this value exists without getting error from JavaScript.

Computed properties can be calculated outside and accessed from the inside of the object
In this example, the [Name] is a computed property of the rank object. The property name is derived from the value of the Name variable. the dynamical approach of changing the names of certain key or value inside an object can a good example to represent this phenomena, as shown below:
let Name = 'h';
const rank = {
a: 1,
b: 2,
[Name]: 3,
};
console.log(rank.c);
4)
Object.keys returns an array of keys after including the object indie the Brackets.
Object.entries it returns an array of the key and the value specifically .

you get the value of the object by using Object.Values and it will return an array of values.

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