I am looking to create an empty data class in JavaScript that can later be filled with JSON data. In C#, I would typically do something like this:
class Person {
string name;
int age;
Person[] children;
var whatever;
}
However, when I try the same approach in JS, I receive an error message stating "Unexpected token. A constructor, method, accessor, or property was expected."
I attempted a different approach by declaring variables using `var` instead:
class Person {
var name;
var age;
var children;
var whatever;
}
My lack of experience with JS makes me unsure if this is the correct syntax since declared variables are usually defined immediately. I'm confused about the error as I believe these are properties, and I am uncertain how the JSON deserializer handles arrays of objects when some properties may be missing from the JSON data.
Could someone guide me on how to address this issue and make it work correctly?