+ 1
What is object in JavaScript?
I searched it on Google and read articles also but it still not clear for me
5 Réponses
+ 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.
+ 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.
0
Read this
https://www.sololearn.com/learning/1151/
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
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 😉