简体   繁体   中英

Is a variable an Object in JS

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 !

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM