-1

I'm currently learning JS, and while working on my project, I was wondering if a variable is by definition an object, or a kind of object, or nothing a all.

I know we can create objects through var, but I'm not sure if a var is always an object.

Thanks for the answers !

Pikatime
  • 11
  • 1

3 Answers3

0

A variable is rather like a bucket, where different values can be put in. An object is such a value.

I know we can create objects through var

Not really. With the var keyword you can declare a variable (a bucket), to create an object you could use an object literal.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

Variables are not classified as objects. They are their own classification as a storage address. Now as Nina said in the comment, objects are types which are in the same category as: array, string, number, and boolean. A variable can hold any of these types and be referenced to in your code.

0

Think of var as a mechanism to create a memorable handle for your primitive and reference values like your object. The var keyword itself doesn't do anything other than declare a handle in a scope and allow you to initialize the handle to the value you desire.

Tafadzwa Gonera
  • 352
  • 6
  • 20