What are variables?
Variables are just containers that store data values.
Just like a bag with some fruits.
They can be declared using the following reserved keywords:
varkeyword to create a variable.
title is the variable name that could be anything, such as i, first_name, lastName, etc.
= operator assigns a value on the right, to the variable on the left, and it’s called an assignment operator.
In a nutshell, the
👉 Variable names can be a short name (a, b) or descriptive (title, first_name).
👉 They can be a combination of letters, numbers, underscores (_) & dollar signs ($).
👉 The first letter of a variable name can’t start with numbers.
👉 They are case sensitive and the
Title are NOT the same variables.
👉 No reserver keywords can be used as a variable name such as
var author; // var author = undefined
The author variable declared without initial value will have a value of
Re-assign a new value to the variable
var keyword after initialization.
The value of the
title will be preserved when creating a same variable without an initial value after it’s initialized.
The value of string type is just a text wrapped with single or double-quotes such as ‘Front-end Developer’, or ‘HTML5 Tutorial’.
The value of number type is a digit without quotes such as 100, 8.14, etc.
A value of Number type inside quotes considered String type as well.
var students = '1000'; // String type NOT Number type