Learn about variables in JavaScript, how to declare them, assign values, and manipulate their content.
- A variable acts like a box or container storing a piece of information known as its value.
- Example:
let box;
- Variable names should be descriptive and relevant.
- They follow the camelCase convention (e.g.,
userName
,totalAmount
). - Restrictions:
- Cannot start with a number.
- Cannot be reserved keywords (like
let
).
- After declaring a variable, we can assign a value to it.
- Example:
let box; box = 8;
- Numbers: Numerical values, can be positive, negative, or decimals.
- Strings: Series of characters enclosed within quotation marks (either single
' '
or double" "
).
- Used to perform arithmetic operations on variables.
- Basic ones include:
+
,-
,*
,/
.