There is some coding in this discussion. Feel free to write them in a REPL or in the comments below.
- How is an object different from an array?
- How does
const
work with objects? - 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.
- What are computed properties? Write an example code.
- What is the difference between
Object.keys
andObject.entries
? Write example code using both of them. - How do we get only the values of an object?
0. Arrays stores a list of data as one variable. Objects store values with their keys.
const arr = ["abc", "abc"]
const obj = {key: "abc", key2: "abc}
1. Even if the Object is const, we can change, add or delete the elements inside the objects.
2. Bracket notation allows you to access properties with special characters in their names, while you can not do this with dot notation.
i.e. we can not use names with space: object.element value but we can use object["element value"]
while coding when you put dot(.) after the name of the object, the list of the possible elements will appear while when you use brackets ([]) it won't show up.
3. Allows you to put an expression in brackets [] , that will be computed and used as the property name
i.e.
let propName = 'c';
const rank = {
a: 1,
b: 2,
[propName]: 3,
};
console.log(rank.c); // 3
4. While Object.keys shows only the keys of the elements, Object.entries shows both keys and values.
5. Object.values