+ 4

Unable to understand "Object" in JS

Since I've started learning JS, I am able to understand each and everything. But when I saw "Objects" in that, I tried to understand it with full concentration, but I failed. So can you please help me. 🙏🙏

12th Jun 2019, 4:11 AM
Atharva Varule
Atharva Varule - avatar
3 odpowiedzi
+ 7
Ok, here we go. As you know, a variable in javascript can store one value. In order to store the first and last names of a person, you would create to variables: var firstName = "John"; var lastName = "Smith"; This works in the short term, but become tedious in the long run. Instead we can make an object(stay with me here). var person = { firstName: "John", lastName: "Smith" } First, we set "person" equal to an object "{}". Within the object, two properties are defined (firstName & lastName). Each receives a value like a normal variable, except instead of using "=", we use":" From here, we can access the properties by using "person.firstName" or "person.lastName" Additionally, you could change one of these value like "person.firstName = 'Jane'". Hope this helps. If you have any more questions, feel free to ask.
12th Jun 2019, 1:29 PM
SuperC
SuperC - avatar
+ 12
Objects are used to store keyed collections of various data and more complex entities. In JavaScript, objects penetrate almost every aspect of the language. So we must understand them first before going in-depth anywhere else. An object can be created with figure brackets {…} with an optional list of properties. A property is a “key: value” pair, where key is a string (also called a “property name”), and value can be anything. We can imagine an object as a cabinet with signed files. Every piece of data is stored in its file by the key. It’s easy to find a file by its name or add/remove a file.
15th Jun 2019, 12:59 AM
Assassin💞[#BeFierce]
Assassin💞[#BeFierce] - avatar
+ 2
Thank you very much😘 I liked your way of explanation
12th Jun 2019, 2:15 PM
Atharva Varule
Atharva Varule - avatar