Lesson 3.1: Variables & Data Types

Objective

Learn about variables in JavaScript, how to declare them, assign values, and manipulate their content.

What is a Variable?

  • A variable acts like a box or container storing a piece of information known as its value.
  • Example:
    let box;

Naming a Variable:

  • 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).

Assigning a Value:

  • After declaring a variable, we can assign a value to it.
  • Example:
    let box;
    box = 8;

Data Types:

  • Numbers: Numerical values, can be positive, negative, or decimals.
  • Strings: Series of characters enclosed within quotation marks (either single ' ' or double " ").

Operators:

  • Used to perform arithmetic operations on variables.
  • Basic ones include: +, -, *, /.