variables

JavaScript Basics: Variables and Data Types

JavaScript Basics: Variables and Data Types

Variables allow us to store and manage data in our code. JavaScript has several types of data we can work with, like strings, numbers, and booleans.

Declaring Variables

In JavaScript, we use let, const, or var to declare variables:

      
        let age = 25;
        const name = "John";
        var isStudent = true;
      
    

Data Types

Example: Variables and Data Types

      
        let message = "Hello, World!";
        const pi = 3.14;
        var isOpen = true;
        console.log(message, pi, isOpen);
      
    

Activity

Try It Yourself!

Declare your own variables for name, age, and isStudent. Log them to the console.

Quiz

Quick Quiz

  1. What keyword would you use to declare a constant variable?
  2. Which data type is used to represent text?
  3. What are boolean values?

Answers: const; string; true and false.