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?
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 .
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));