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
Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.$ Check price