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?
While an object is a collection of properties, and a property is an association between a name (or key) and a value.
1.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 const variable.
Only with bracket notation we can access object properties using variable: Example Object[variable] this help dynamically accessing properties like looping and assigning computed properties
dot notation is more readable and easier. You can directly access properties by calling the key : Example Object.key //will return value
Computed properties use an expression in brackets []. Then use the result of the expression as the property name of an object.
an example would be:
let x = "age";
Const person={
name : "Ahmed",
[x] : 24,
}
4.Object.keys will return keys of object inside an array example: Object.keys(object) = ["key1", "key2"]
Object.enteries will return each both keys and values inside an array example Object.entries(object) = [ ["key1","value1"], ["key2","value2"] ]