APPLY NOW HERE :: FREE REGISTERATION ONLINE
Want to know more about us and our multimedia, animation & web design courses, feel free to Contact Us. We would love to hear from you.
JavaScript variables are containers for storing data values.
In below example, a, b, and c, are variables:
Example
var a = 4;
var b = 7;
var c = a + b;
JavaScript variables can hold numbers like 50 and text values like "Pawan Negi". In a programming language, text values are called text strings. JavaScript can handle many types of data, but for now, just think of numbers and strings. In JavaScript, Strings are written inside double or single quotes. Numbers are written without quotes. If you put a number in quotes, it will be treated as a text string.
Example
var pi = 60.2;
var person = "Pawan Negi";
var answer = 'Yes I am!';
Creating a variable or declaring a variable is same in JavaScript.
We create a JavaScript variable with the var keyword:
var myName;
After the declaration, the variable doesn't have any value. (Technically it has the value of undefined)
To assign a value to the variable, use the equal sign:
myName = "Rahul";
You can also assign a value to the variable when you declare it:
var myName = "Rahul";
In the example below, we create a variable called myName and assign the value "Rahul" to it.
Then we "output" the value inside an HTML paragraph with id="demo":
Create a variable called age, assign the value 21 to it, and display it.
Display the sum of 2 + 8, using two variables a and b.
Create a third variable called c, assign a + b to it, and display it.
Mobile Number : 9891 222 738, 9891 50 1300
E-mail : contactbapugraphics@gmail.com
ADDRESS: 263, First Floor,Pocket H-17, Sector 7,
Near Rohini West Metro Station, Rohini, Delhi - 110085
Opposite Metro Pillar No. 425
Day | Timing |
Monday To Friday | 8:00 Am To 8:00Pm |
Saturday & Sunday | 8:00 Am To 5:00Pm |
Want to know more about us and our multimedia, animation & web design courses, feel free to Contact Us. We would love to hear from you.