Variables in JavaScript

The purpose of variable to store information or any value. A variable is symbolic name that represents some data that you set. For example, age is a variable and different persons have different age. JavaScript is case sensitive, that means that myvars and MyVars are two different names to JavaScript because they have different capitalization. JavaScript accepts unique variable names. Variables have much type of values (like numeric, string and logical values).Variable Name Guidelines>
  • Must start with alphabetical character>
  • Variable names are case-sensitive>
  • can't contain any periods or type-declaration characters>
  • must be unique within the same scope>
  • must be 255 characters or less>
  • Variable must begin with a letter or the underscore character

How to use variables?> In Javascript you can declare variable with var statement like:

var age = 5;
var name = "Chris";> You can also create a variable without the var statement like:
age = 5;
name = "Chris";:
<Script language="javascript">
name=”my name is mark”;
document.write(name);
</script>

In this example we have defined two variable name, age, name has string value “mark” but age has numeric value 35, The output will display as below: >

my name is mark

Another Example of JavaScript

<Script language="javascript">
value1=35;
value2=88;
result=value1+value2;
document.write("Result is ");
document.write(result);
</script>

Output

Result is 123

Bookmark This Page

Link Partners