What JavaScript is & how it runs
Understand the idea
A button looks finished, but clicking it does nothing. HTML describes the button; something still has to respond to the click.
Instructions, not mind reading
You do not need to know how a processor works to start. You do need to be precise about each step: read a value, make a decision, or display a result. A small program lets you check that precision without juggling a whole application.
The language and its surroundings
HTML describes a page's structure. CSS controls its presentation. JavaScript can read values, make decisions, and change the page while someone uses it. JavaScript also runs outside browsers: Node.js gives the same language access to a different environment, including files and server connections.
| Part | What it does | A concrete job |
|---|---|---|
| HTML | Describes the document | Provides a button and its label |
| CSS | Controls presentation | Gives that button its size and color |
| JavaScript | Expresses behavior | Responds to the button being pressed |
| Browser APIs | Provide browser capabilities | Let JavaScript find the button or start a timer |
| JavaScript engine | Parses and executes the language | Runs a function when the program calls it |
Before the first line runs
The engine checks that your code can be parsed before executing it. A syntax error can prevent that script from starting. Once execution begins, ordinary run in order. A runtime error stops the current execution path unless something handles it; earlier work is not undone.
Parsing means checking whether the written instructions follow the language's grammar. That grammar is called syntax. Execution means carrying out valid instructions. A misspelled punctuation mark can stop parsing; a missing value can cause trouble later during execution. They are different moments, so the fix starts by noticing when the program stopped.
Describing work versus doing it
A declaration describes work. It does not perform that work until you call the function. That distinction explains many silent buttons: the handler exists, but nothing has registered or called it.
Read the example in order
The browser supplies things such as document, events, and timers. They are not all built into the JavaScript language. Copying browser code into a server can fail because the environment has no document to inspect. When code fails, check both the instruction and where you are asking it to run.
Read the live example from top to bottom, but skip the function body until you reach its call. When the call finishes, continue with the next line below it. The console is a place to inspect messages while you work; printing a message there does not put it on the visible page.
Mental model
EXECUTING CODE
function showStatus(){ console.log("Ready");}
console.log("Starting");showStatus();
console.log("Finished");CALL STACK / LAST IN, FIRST OUT
01 / 14Start script
Live example
Predict the three lines before running. Remove the parentheses from showStatus() and compare what disappears.
Your console output appears here.
Guided challenge
Make the function run
The console skips Ready. Change the function reference into a call.
Your console output appears here.
EXPECTED CONSOLE OUTPUT
Starting Ready Finished
Hints 0/2
Use all hints or make 3 failed runs (0/3).
Free sandbox
Make a variation, test an assumption, or break the example on purpose. This draft is saved separately.
Your console output appears here.
Quiz
A quick check for understanding. Retry as often as you like; your learning path stays open.
Ready to call this one understood?
Mark this lesson complete to earn 100 XP. You can always revisit it.