JavaScript Basics1/21

Your First Code

Welcome to JavaScript! 🎉

JavaScript is the language that adds behavior to the web. HTML is the content, CSS is the look, JavaScript is the brains. Every button you click, menu you open, or form you submit is powered by JavaScript.

Why Learn JavaScript?

  • 🌐 Runs Everywhere: Every browser understands it—no installs.
  • 💼 High Demand: Frontend, backend (Node), mobile, desktop—all use JS.
  • 🚀 Versatile: Animations, dashboards, games, AI demos—you name it.

Mental Model

  • Think of JavaScript as a helpful narrator that can read and speak on the page.
  • Your first tool to make it speak is console.log(), which prints messages.

Your First Command: console.log()

Think of console.log() as JavaScript's way of talking to you. It displays messages on the screen (the “console”).

console.log("Hello, World!");

When you run this code, you'll see: Hello, World!

How It Works

PartWhat It Does
consoleA built-in tool for output
.log()The "display this" command
"Hello, World!"The message to show

Important Rules ⚠️

  1. Use quotes for text: "Hello" or 'Hello'
  2. Always use parentheses: console.log(...)
  3. Finish with a semicolon: ; (good practice)

Common Mistakes

  • console.log(Hello) — Missing quotes
  • Console.log("Hi") — Capital C, JavaScript is case-sensitive
  • console.log("Hi") — Correct

Quick Checklist

  • Did I open/close quotes?
  • Did I open/close parentheses?
  • Did I type console in all lowercase?

Your Turn!

Display the message "Hello, World!" using console.log()