DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Datatypes And Variables In Javascript

12.26.2011
| 2223 views |
  • submit to reddit
        JavaScript variables have an identifier, scope, and a specific data type. Because the language is loosely typed, the rest, as they say, is subject to change without notice.

Variables in JavaScript are much like those in any other language; you use them to hold values in such a way that the values can be explicitly accessed in different places in the code. Each has an identifier that is unique to the scope of use (more on this later), consisting of any combination of letters, digits, underscores, and dollar signs. An identifier doesn’t have a required format, other than it must begin with a character, dollar sign, or underscore:

_variableidentifier
__variableidentifier
variableIdentifier
$variable_identifier
var-ident

Starting with JavaScript 1.5, you can also use Unicode letters (such as �) and digits, as well as escape sequences (such as \u0009) in variable identifiers. The following are also valid variable identifiers for JavaScript:
_�valid
T\u0009
Use special characters with caution, though, as some tools such as debuggers may have difficulty with them.

JavaScript is case-sensitive, which means it treats upper- and lowercase characters differently. For instance, JavaScript sees the following two variable identifiers as separate variables:
stringVariable
stringvariable

<a href="http://www.java-forums.org/blogs/spring-framework/"><strong>Spring Framework</strong></a>