What Is Variable

In computer programming , a variable is a keyword which assign a value . Variable value can be changed according programming conditions .


Variables syntax are different according to programming language . Some for example as follows

  • In java script word “var” is used to declare a variables
  • In c++ language self defined word is used as variables but only difference is type of variables declaration .
  • In jQuery “$” sign is used to declare a variable . $num1 = $num2 + $num3 ;

Suppose a = 2; in this case “a” is variable name and 2 is value .


How It works

A Variable assign a value and passed them when it is called . Value is the stored data which is used in the program when it is required .

Assume a box ,which is used to store something . In this box stored some cookie . In programming this box is as a variable which can store values . And cookie is as value of  the var .

In this box ( variable ) , value ( cookie ) can be changed .


In this article we take example of  java script variables

<!DOCTYPE html>
 function sum()
var a = 5 ; 
var b = 6 ;
var c = a + b ;
window.alert("sum of two numbers is" + c ); 
<button id="text" onclick="sum()"> Button </button>

In this example world “var” is used to declared variable . a , b and c is used for variable names .

var a = 5 ;
var b = 6 ;
var c = a + b ;

var a assign value “5” ,var b assign value = 6 and var c assign value sum of var a and var b .

Check The Example

This html code display the button on web browser  . When you click on the button , var c value passed to window alert to display .


When you click on ” button ” , massage box is display and massage is “Sum of two numbers is 11” .