Lesson 1: Your First JavaScript Program - Hello World
What You'll Learn
- How to create a JavaScript file
- How to write your first line of code
- How to run a JavaScript program
- What
console.log()does
Why This Matters
Every programmer starts with a "Hello World" program. It's a simple way to make sure everything works and to see how code turns into output on your screen.
Step 1: Create Your First JavaScript File
- Open VS Code and open your
node-lessonsfolder - Create a new folder called
lesson-01in the Explorer panel - Create a new file: Right-click on
lesson-01folder → New File - Name it:
hello.js
- The .js extension tells your computer this is a JavaScript file
Step 2: Write Your First Code
Type this into your hello.js file:
console.log("Welcome to programming!");
console.log("My name is [Your Name]");
console.log("I am learning JavaScript");
What Happens When You Run This?
Each console.log() statement prints on a new line:
Welcome to programming!
My name is [Your Name]
I am learning JavaScript
Understanding How Code Runs
When you run a program:
- The computer reads your code from top to bottom
- It executes each instruction one at a time
- The output appears in the terminal
Think of it like following a recipe - you do step 1, then step 2, then step 3, in order.
Step 5: Common Mistakes and How to Fix Them
Mistake 1: Forgetting Quotation Marks
console.log(Hello); // ❌ ERROR - missing quotes around Hello
console.log("Hello); // ❌ ERROR - missing closing quote
Fix: Always use matching quotation marks around text:
console.log("Hello"); // ✅ Correct
console.log('Hello'); // ✅ Also correct
Mistake 2: Typos in Keywords
consol.log("Hello!"); // ❌ ERROR - typo in "console"
console.lag("Hello!"); // ❌ ERROR - typo in "log"
Fix: Make sure spelling is exact:
console.log("Hello!"); // ✅ Correct spelling
Exercise 3: Print a Story
Write a program that prints a very short story, one line at a time.
Key Concepts Summary
| Concept | Definition | Example |
|---|---|---|
| Statement | A single instruction in code | console.log("Hi"); |
| String | Text data in quotation marks | "Hello" or 'Hello' |
| Function | A reusable piece of code that performs an action | console.log() |
| Console | The terminal/output area where text appears | The black/white text area at bottom of VS Code |
What You Learned
- ✅ How to create a
.jsJavaScript file - ✅ How to use
console.log()to print output - ✅ How to run JavaScript code with Node.js
- ✅ How to read error messages and fix simple mistakes
- ✅ That code runs from top to bottom, line by line
What's Next?
In the next lesson, you'll learn about variables - how to store and reuse information in your programs.