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?
We are the people of group 5 (Dilara Katuk, Dilara Fırtına, Abdul Hafiz Mhammadah, Berfin Karaman), and here are our answers:
0. The main difference is the item storing. Iterating through values is different, for example, we can use "for" loops directly for arrays while we would need additional functions to use "for" loops.
customer[customerName];
//=> "abc"
customerName= "abc";
customers.customerName;
//=> undefined
const myPropertyName = 'c'
const myObject = {
a: 5,
b: 10,
[myPropertyName]: 15
}
console.log(myObject.c) // prints 15
4. Object.key returns just the keys while object.entries return the keys and the values.
const object1 = {
student1: 'Dilara',
student2: 'Dilara 2',
student3: 'Berfin',
student4: 'Abdul'
};
console.log(Object.keys(object1));
// expected output: Array ["Dilara", "Dilara 2", "Berfin", "Abdul"]
console.log(Object.enteries(object1));
// expected output:
// "student1: Dilara"
// "student2: Dilara 2"
// "student3: Berfin"
// "student4: Abdul"