rockstar
rockstar

Reputation: 3538

Javascript variables of class type

I am seeing a piece of code . Its a .js file . I see that this file has the following kind of variable declared

var abc = {};
abc.Version="xxx";
abc.path="yyyy"

In other words the variable is used like a class . In saw the Javascript tutorials : here & here . But i see no mention of a class type variable .

What is it ? Wondering why isnt it mentioned in these websites .

Upvotes: 0

Views: 74

Answers (3)

HartleySan
HartleySan

Reputation: 7830

The variable abc is an object, but there are no classes in JS. JS uses prototypical objects, not classical objects, which is what languages like Java and C++ do.

With JS, you can declare an object like your first line of code above, and then dynamically declare properties of that object on the fly, as is the case in lines 2 and 3 of your code above.

Upvotes: 1

Casey Flynn
Casey Flynn

Reputation: 14048

It is an object literal. What you're seeing on lines #2/3 are properties and associated values being dynamically added to it.

Upvotes: 3

Jim Rubenstein
Jim Rubenstein

Reputation: 6930

they are properties on your object

Upvotes: 0

Related Questions