+ 2
what is the difference between struct and object
i know c programming languege.now i learn javascrip in this case if similarity between struct and object i can learn easily.
3 Respuestas
+ 6
They both are a set of properties, key-value pairs.
In C, you have to define the struct before using it. In JavaScript, you can add new keys easily.
In C, you need to declare functions in global scope and accept the struct as parameters to process them.
In JavaScript, you can define prototypical method for objects.
https://code.sololearn.com/WHv9qE16JYxC/?ref=app
From ES6 onwards, you can even use new syntax namely class.
https://code.sololearn.com/WAjJkQ8RXk40/?ref=app
This is a good video to learn about class :
https://www.sololearn.com/post/38381/?ref=app
+ 5
Stuct shares similiraties with objects, the main similiraties are:
they are a user defined type.
They bring relatable data together in one place.
However an object is even more, they also contain functions/methods that are meant to work with the data inside of it, generally this data can only be accessed through the methods.
Since you have taken C ill assume you know what a class is, in java/JavaScript an Object is a class that has been constructed and assigned to a variable.
+ 2
The first is a value type and the latter a reference type .....🤔