codescracker


javascript

JavaScript Variables



« Previous Tutorial Next Tutorial »


JavaScript variables are basically the containers for storing the data values in a JavaScript program.

Declare Variables in JavaScript

To declare variables in JavaScript, use var keyword. Here is an example shows how to declare variables in JavaScript:

var employee;
var name;

You can also declared multiple variables at the same line (with only one var keyword) as shown in this example:

var num1, num2, num3;

JavaScript Variables Example

Here is an example uses three variables namely a, b, and c:

<!DOCTYPE html>
<html>
<head>
	<title>JavaScript Variables Example</title>
</head>
<body>

<p id="variable_para1">i will be replaced</p>
<script>
	var num1 = 500;
	var num2 = 600;
	var res = num1 + num2;
	document.getElementById("variable_para1").innerHTML = res;
</script>

</body>
</html>

Here is the output of the above JavaScript program:

javascript variables

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test