Home Tutorial Javascript Javascriptbasics JavaScript Variables


Share on Google+Share on Google+
JavaScript Variables
Posted on: November 6, 2009 at 12:00 AM
JavaScript Variables: In this tutorial you will come to know about how to declare variables, how to display the values of a variable, what is the meaning of dynamic typing of variables in JavaScript.

JavaScript Variables:

Variables are like containers, which contains a value. In JavaScript variables dependent on the value, not on the datatype that means variables are of  dynamic typing. Variable names are case-sensitive and this should be start with either a letter or underscore.

We can use var statement  to declare a variable as follows.

var x;

var variable;

We can assign any type of value at the time of declaration like:

var x=23;

var variable="string";

We can ignore  the var statement at declaration time by assigning value to a variable.



is same as the above given example

Example 1:

Variables in JavaScript
<script type="text/javascript">
var x=12;
document.write("Value of x is " + x);
document.write("<br/> Value of y is " + y);
x="String type value";
document.write("<br/>New value of x is " + x);
document.write("<br/>New value of y is " + y);


Value of x is 12
Value of y is String
New value of x is String type value
New value of y is 343


Related Tags for JavaScript Variables:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 6, 2009

Recommend the tutorial

Advertisements Advertisements