๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐ข๐ฏ๐ท๐ฒ๐ฐ๐๐ ๐ฎ๐ป๐ฑ ๐ ๐ฒ๐๐ต๐ผ๐ฑ๐ ๐ ๐ฎ๐ฑ๐ฒ ๐ฆ๐ถ๐บ๐ฝ๐น๐ฒ
A JavaScript object is a bag of named values. Use them to model real things. Think of a car or a user.
Use dots to read a property. Use brackets if the key has spaces or exists as a variable.
A method is a function inside an object. The word this points to the object you call. Use regular functions for methods. Use arrow functions for callbacks.
Use a constructor function to make many objects. Use the new keyword. It builds the object and returns it.
Put objects inside other objects. Use optional chaining (?. ) to stop your code from crashing when data is missing.
Use these tools to manage data:
- Object.keys gives you names.
- Object.values gives you data.
- Object.entries gives you both.
- The spread operator (...) merges objects.
Keep these warnings in mind:
- Two objects with the same data are not the same. JavaScript checks the memory spot.
- typeof null says it is an object. It is not.
- Objects pass by reference. Changes inside a function affect the original object.
Build a project. Model a shopping cart or a playlist. Break things to learn fast.
Source: https://dev.to/ilyas_elaissi/javascript-objects-methods-explained-with-examples-56cg