05.01.2013 Views

hide - Understanding jQuery

hide - Understanding jQuery

hide - Understanding jQuery

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

What Exactly is a JavaScript Variable?<br />

Learning isn’t always about explaining new complex subjects. Sometimes it’s about bringing to<br />

your attention the deeper details of the already known. In-depth understanding makes programming<br />

more interesting. It’s easy to think that you know everything about variables. But<br />

there are many details that often slip from the viewfinder of an untrained eye.<br />

While working on Revision Two of this book, I have added more chapters to the JavaScript<br />

Bootcamp to talk more about the basics of JavaScript programming. One of the subjects deals<br />

with JavaScript variables.<br />

One of the goals with my writing is to give a deeper insight into simple concepts. I believe<br />

that by reaching down to the very reason for why something works a certain way the reader is<br />

given an opportunity to become a better JavaScript programmer.<br />

When teaching a computer language such as JavaScript numerous tutorials talk about using<br />

variables in terms of showing how they work. But little is said about what they are. We are<br />

often told that we can define variables using the var keyword. But understanding what they are<br />

and where they come from gives us a deeper insight into JavaScript programming. In fact,<br />

many JavaScript concepts, such as objects, are much easier to understand if we can compare<br />

them with variables.<br />

Are They Variables or Objects?<br />

* * *<br />

Because everything in JavaScript is an object this sometimes creates confusion among the beginners<br />

who are seeking to understand JavaScript data types. If everything is an object, then<br />

what is a variable? And if a variable is indeed an object, then why are we using the keyword<br />

named var to define it? Wouldn’t something like obj be more appropriate?<br />

The answers to such questions are often determined by creators of the language specification<br />

itself. The fact that someone decided to create a specification does not guarante that this specification<br />

will be ideal. Regardless, when it comes to any data in any language, it is always tied to<br />

the same concept: all data is stored in computer memory on the microprocessor.<br />

Keep in mind that all variables are physically stored in computer memory at random addresses.<br />

When we access a variable, we access the part of computer memory it is stored in. A variable<br />

is stored at a unique and random memory address chosen by the operating system.<br />

We’ll get to how variables are physically stored in computer memory in just a moment.<br />

24

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!