Lesson 1 of 10

JavaScript Foundations

Lesson 1: Your First Code

Welcome. We are starting from scratch with Node.js, variables, and console.log.

Learning Goals

Example

When we write this, we mean we are saving text inside a variable and printing it.

// Save as lesson1.js
let message = "Hello, Patricia";
console.log(message);

Line by line:

Tip: Run node lesson1.js in your terminal.

Real-Life Translation

Think of a variable like a labeled container.

So when we write code, we are really saying: "Store this value, then show it."

Deeper Explanation

In this first lesson, your main skill is not typing fast. Your main skill is understanding what each line tells the computer to do. JavaScript reads your instructions from top to bottom. So if you create a variable first and print second, the output makes sense. If you try to print before creating the variable, the program fails because that value does not exist yet.

That is why we are keeping this lesson very simple: one variable, one print, clear meaning. Once this pattern is natural to you, every bigger topic becomes easier because most programs are still built from the same two actions: store values and use values.

Common Beginner Mistakes

  1. Forgetting quotes for text: Hello should be "Hello".
  2. Forgetting semicolons in this track where we keep code explicit.
  3. Typing console.log(message) before creating message.

Practice

  1. Create a variable called name and store your name.
  2. Create a variable called city and store your city.
  3. Print both values using console.log.
  4. Create a variable favoriteFood and print: I like ....

Homework

Create a file named about-me.js with 4 variables: name, city, favoriteFood, and bestSubject. Print all of them one by one.

Answer Guide
let name = "Patricia";
let city = "Kampala";
let favoriteFood = "Rolex";
let bestSubject = "JavaScript";

console.log(name);
console.log(city);
console.log(favoriteFood);
console.log(bestSubject);
Next Lesson →