Literals are fixed values of either numbers (with or without decimals), or strings.
// numerical literals 3.14; 48; // Strings "Hello World!"; 'Hello Mars!';
Literals won't do much on its own, so let's take a look at variables, which are containers that can store literals.
Variables store data values such as literals. They can also be set to expressions, which are evaluated and placed into the variable.
To define a variable, we use the
var keyword with the assignment operator
// Initialize variable count and set it to 0 var count = 0; // Or just initialize the variable var count;
In the second initialization, the variable
count is initalized to
You can also declare multiple variables while using the
var keyword just once.
var price = 5, quantity = 23, total = 50; var price, quantity, total;
var keyword. We'll talk about the different data types and typecasting in the next section.
Here are some guidelines to follow when assigning a variable name:
When deciding on a variable name, it's important to be clear and descriptive. Names like
pre are too short and don't convey any information.
Variables of more than one word should have a upperCamelCase format. This means that the first word is all lowercase, and any subsequent words have their first letters capitalized. For example, a variable that holds the number of remaining books would look like
Relieve your stress, back, neck and sciatic pain through 1,782 acupuncture points for immediate neck pain relief. Made for lower, upper and mid chronic back pain treatment, and improves circulation, sleep, digestion and quality of life.$$ Check price
This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.$ Check price