+ 1

What is object in JavaScript?

I searched it on Google and read articles also but it still not clear for me

31st Aug 2021, 6:58 AM
Riya Ranka
5 Antworten
+ 2
In simple words I can say like object is best for grouping the variables and functions. For example let rectangle = { width: 40, height: 50 } let square = { sides: 5 } let employee = { name: "Raman", salary: 50000 } console.log("Employee name is "+employee.name) insted of writing sides of squares , data of employees and height and width of rectangle in variable it's nice to group them.
31st Aug 2021, 7:20 AM
Abhiyantā
Abhiyantā - avatar
+ 1
Objects are like classes in some other languages. I think best part of language for creating games are objects/classes. For example you want to create a racing game. You want to have lots of different cars. Is it better that you declare lots of variables??? Or make a clean code like this: function car(name, speed) { this.name = name; this.speed = speed; this.speedUp = function() { this.speed += 1; } } after that you can declare lots of car just like this: var player = new car("lambo", 300); var enemy1 = new car("Toyota", 250); ... and you can use functions(methods) of objects like this: player.speedUp(); you are free to declare variables insted of objects but thats really cleaner and faster for some times.
31st Aug 2021, 7:27 AM
Arshia Tamimi
Arshia Tamimi - avatar
31st Aug 2021, 7:15 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
JavaScript object is an unordered collection of key-value pairs Example : let person = { firstName: 'Armaan', lastName: 'Malik' }; Where, person - is the object Name firstName and lastName - are the Keys Armaan , Malik - are Values
31st Aug 2021, 11:57 AM
Ankita Malik
Ankita Malik - avatar
0
In my opinion object are the sets of variable and functions Or U can say they are group of simalar slaves, U can use them like a boss 😉
2nd Sep 2021, 5:02 AM
Manvendra Yadav
Manvendra Yadav - avatar