Variable

Variables are declared using the keyword “var”. For instance, the following statement creates a variable named “message”:

message holds the value “undefined” because no initial value is assigned to it. To notice that, if a variable is undeclared, it’s also undefined.

However, an undeclared variable is different from an variable holding “undefined” value. Trying to use un undeclared variable may cause exceptions.

Variable is defined at where “var” statement is executed. Do not access a variable declared afterwards because at that point, the variable isn’t available yet.

It’s noteworthy that assigning value to an undeclared variable accidentally creates a variable in the global scope.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s