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.
x=23;
variable="string";
is same as the above given example
Example 1:
<html>
<head>
<title>
Variables in JavaScript
</title>
</head>
<body>
<script type="text/javascript">
var x=12;
document.write("Value of x is " + x);
y="String";
document.write("<br/> Value of y is " + y);
x="String type value";
document.write("<br/>New value of x is " + x);
y=343;
document.write("<br/>New value of y is " + y);
</script>
</body>
</html>
Output:
Value of x is 12
Value of y is String
New value of x is String type value
New value of y is 343
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.