GK SOLUTIONS
AI • IoT • Arduino • Projects & Tutorials
DEFEAT THE FEAR
← Back to All Lessons

📦 Lesson 2: JavaScript Variables & Data Types

⏱️ Estimated time: 20 minutes | Difficulty: Beginner

Storing Data

Variables are containers for storing data values. In JavaScript, we use let, const, or var to declare variables.

Hello, JavaScript!

Let's write your first JavaScript program:

<script>
  console.log("Hello, JavaScript!");
</script>

Where to Put JavaScript

In HTML Head

<head>
  <script>
    console.log("Runs first");
  </script>
</head>

In HTML Body

<body>
  <script>
    console.log("Runs after HTML loads");
  </script>
</body>

External File

<script src="app.js">
</script>

Using the Console

The console is where JavaScript displays messages. Open it:

  1. Right-click on a webpage → "Inspect" (or press F12)
  2. Click the "Console" tab
  3. You'll see messages from JavaScript

Your First Real Program

<!DOCTYPE html>
<html>
<head>
  <title>My First JavaScript</title>
</head>
<body>
  <h1>Welcome!</h1>
  
  <script>
    console.log("JavaScript is running!");
    console.log("I can write messages here");
    console.log("This is awesome!");
  </script>
</body>
</html>

Output in console:

JavaScript is running!
I can write messages here
This is awesome!

✅ Quick Quiz

❓ How do you write JavaScript?

❓ What does console.log() do?

❓ How do you open the console?

🎯 Challenge

Create an HTML file with JavaScript that:

  1. Logs 3 different messages to the console
  2. Use console.log() for each message
  3. Open the console and verify you see all 3 messages
← Previous: What is JavaScript? Next: Variables →