Variables in JavaScript
- 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>
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>
value1=35;
value2=88;
result=value1+value2;
document.write("Result is ");
document.write(result);
</script>
Output
Result
is 123