Variable definition – In programming, a variable is a value that can change, depending on conditions or on information passed to the program. In C Language variable is a named location in a memory where a program can manipulate the data. This location is used to hold the value of the variable. Its just like in Algebra,
Commone Rules for creating names for variables (x,y,z ..) are :
- Identifier Names can contain letters, digits, underscores, and dollar signs.
- Identifier Names must begin with a letter (price,totalPrice,price2 …)
- Identifier Names are case sensitive (x and X are different variables)
- variable will declare with prefix var like var price
Example declaring variable
var price = 100; (valid)
var 2price= 100;(not valid)
var person = "Aayush";(valid)
We can also declare variable in single line like
var person = “Sanjay”, BikeName = “Bajaj Pulser”, price = 70000;
Create a page variable.html copy and paste below code and save and run.
<input type="text" id="name" /> <br/>
<input type="submit" onclick="variableAlert()" value="Submit">
var name = document.getElementById('name').value;