Lesson 3.7 - Review

Variables

  • A variable is like a container for storing data.
  • Variables are used to update, change, and manipulate data within our webpages.
  • Data types that can be stored in variables include:
    • Strings (e.g., let name = "Mario";)
    • Numbers (e.g., let students = 30;)
    • HTML Elements (e.g., let divTag = document.querySelector("div");)

Declaring and Selecting Variables

// To save an HTML tag in a variable:
let paragraph = document.querySelector(".container");

// To select an element with a specific class:
let image = document.querySelector(".firstImg");

💬 Console Log

  • To debug and check the values stored in your variables, use the console log.
// To log a value to the console:
console.log(yourVariable);
  • The console is a development tool that is not visible to end-users.

Happy Coding!