Variable in Javascript
What is Variable?

Variable is just like a container for data. We can say we store data in a variable.

How to declare/Create Variable in Javascript.

var x;
Where x is a variable name. we can take variable as meaningful like var address.

Note:- variable name must be start with letter or underscore. Like
var _fname;
var fname;

is valid variable name.

Javascript is case sensitive. So
var x
var X
has two different variable.

If we assign a value to the variable then it is not necessary to declare with var.
X=50;

Example 1:- Simple Javascript Programme to print adding of two Number.

<html>
<head>
<title>My JavaScript Programme</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var num1=4;
var num2=6;
var num3;
num3=num1+num2;
document.write(num3);
</script>
</body>
</html>

Alert() popup.

Alert is a popup box. This is basically use for print output .

Example 2:- Programme to use of alert popup.

<html>
<head>
<title>My JavaScript Programme</title>
</head>
<body>
<script language="javascript" language="text/javascript">
num1=4;
num2=6;
num3=num1+num2;
alert(num3);
</script>
</body>
</html>

Prompt() popup.

prompt popup is use to input value.

Example 3:- Programme to use of prompt popup.

<html>
<body>
<script language="javascript"language="text/javascript">
var x;
x=prompt("Enter Number","0");
document.write(x);
</script>
</body>
</html>


Previous
Next