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?
Group Members: Beyza Fatma Bostancı, Hamza Aymen, Özge Erdemir
1.In JS, almost everything is an object. Arrays are more like a list. Objects store a collection of data. Objects represent a special data type. Arrays are a special type of variable.
2.The const keyword makes a variable itself immutable, not its assigned content. When the content is an object, this means the object itself can still be altered. Therefore, it's possible to change the content of the object that is declared with const variable, but you cannot assign a new object to a a const variable.
3.Bracket syntax allows us to access object properties using variable. When working with dot notation, property identifies can only be alphanumeric (and _ and $). Properties can’t start with a number.
Dot notation:
Property identifies can only be alphanumeric (and _ and $)
Property identifiers cannot start with a number.
Property identifiers cannot contain variables.
OK — obj.prop_1, obj.prop$
Not OK — obj.1prop, obj.prop name
Bracket notation:
Property identifiers have to be a String or a variable that references a String.
It is okay to use variables, spaces, and Strings that start with numbers
OK — obj["1prop"], obj["prop name"]
When working with bracket notation, property identifiers only have to be a String. They can include any characters, including spaces. Variables may also be used as long as the variable resolves to a String.
EXAMPLE:
let obj = {
cat: 'meow',
dog: 'woof'
};
let dog = 'cat';
let sound = obj[dog];
console.log(sound);
// meow
4.A computed property is a property that calculates and returns a value, rather than just store it
5.Object.keys() return an array of keys only , while Object.entries() return an array of key value pairs
code example :
let x = {
name:adam,
age:21
}
Object.keys(x) => ['name','age'];
Object.entiers(x) => [[‘name','adam'],['age',21]];