+ 3
Please anyone explain what are objects in JS?
Objects
7 Respuestas
+ 3
Fems , I'll say have patience. Give one more try to lesson. If you fail to understand a "specific concept" you can ask me anytime.
If you be specific in asking what you don't really understand ,I'll explain it in more details. But as Object itself is a very large topic It's not possible to cover just in few (1024) chars.
+ 4
I think Objects are used to store data values.
Then what is the difference between variables and objects?
I'm confused
+ 4
Thanks Omkar
+ 3
Fems ,
An object is collection of both data members and methods.
Data members are like individual property of an object.
Methods are the function that are bound to object and manipulate its own data.
An example may make this clear.
Ok, the good ol' OOP example , Car..
+data members :
color
maxSpeed
brand
millage
etc.
+methods :
run()
accelerate()
stop()
stear()
reverse()
etc.
There are many ways to create objects in JS. You can use the one that better suits your need.
+What advantage will an object offer?
Imagine you are making a car game in which there will be several cars :
1.Every object is unique - every car being unique, if you stop one car it'll not affect state of another car. If one runs out of fuel this will not have effect on another.
2.Less variables - If you want to do things w/o objects there will be many variables. for example car1Color, car2Color and at one point I this code will become extremely unmanageable.
Well many advantages are there.
Char limit reached 😅
+ 3
narayanaprasad Thank you
+ 2
Have you read about objects in course.? May I know what have you understand about it so far?
Objects in javascript or any other language are just like real world entities. They have their own state (properties) and behavior (methods)
+ 2
You may find answer in https://www.w3schools.com/js/js_object_definition.asp