JavaScript - Introduction
Overview
Estimated time: 20–30 minutes
JavaScript is the language of the web. It runs in browsers, on servers (Node.js), on the edge, and in native shells. In this track you’ll learn modern, practical JavaScript with complete, runnable examples—focused on browser JavaScript for now.
Learning Objectives
- Describe where JavaScript runs and how it’s delivered to users (inline vs external files).
- Write and run your first script in the browser console and inside a page.
- Know the next steps: enabling JS, script placement, syntax, and your first program.
Prerequisites
- None. This is the first lesson.
Why JavaScript?
- Ubiquitous: every major browser ships a JS engine.
- Event-driven UIs and rich Web APIs (DOM, Fetch, Storage, Workers, Canvas, etc.).
- Mature tooling and ecosystem, with modern language features (ES2015+).
Example
console.log('Hello, JavaScript!');
Expected Output:
Hello, JavaScript!
Common Pitfalls
- Using
var
instead of block-scopedlet
/const
. - Confusing
==
with===
(coercion). Prefer strict equality (===
).
Checks for Understanding
- Where does JavaScript execute when you load a web page?
- What’s the difference between inline scripts and external script files?
Show answers
- In the browser’s JavaScript engine (e.g., V8, SpiderMonkey, JavaScriptCore).
- Inline scripts live inside the HTML; external scripts are separate
.js
files linked with<script src>
. External files improve caching and organization.
Exercises
- Open DevTools → Console and run
console.log('Hello')
. - Create a simple page and add a
<script>
tag that logs your name.