Object
1. What is an Object?
// Do you need to declare multiple variables like this every time? let userFirstName = 'Ella'; let userLastName = 'Choi'; let userEmail = 'ella@gmail.com'; let userCity = 'Seoul'; let userFirstName = 'Chloe'; let userLastName = 'Kim'; let userEmail = 'chloe@gmail.com'; let userCity = 'Seoul';let user = { // create object with curly braces firstName: 'Ella', // separate pairs of names and values with ',', separate names and values with ':' lastName: 'Choi', // here lastName is the key, 'Choi' is the value email: 'ella@gmail.com', city: 'Seoul', };
2. Two Ways to Access Object Values
Dot notation: object + .(dot) + key value
Bracket notation: key value as 'string' inside square brackets
3. Various Ways to Handle Objects
Bracket notation: must be used when key values change dynamically
You can also add values using dot/bracket notation
You can also delete properties using the delete keyword
You can check if a key exists using the in operator
4. Common Mistakes When Writing Strings
Last updated