Skip to content
engineering workbench.by StudyPort Academy
Learning path
Foundations15 minLESSON 01 / 34

What JavaScript is & how it runs

01

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.

Which part of the web does which job?
PartWhat it doesA concrete job
HTMLDescribes the documentProvides a button and its label
CSSControls presentationGives that button its size and color
JavaScriptExpresses behaviorResponds to the button being pressed
Browser APIsProvide browser capabilitiesLet JavaScript find the button or start a timer
JavaScript engineParses and executes the languageRuns 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.

02

Mental model

EXECUTING CODE

1
function showStatus(){
2
 console.log("Ready");
3
}
4
console.log("Starting");
5
showStatus();
6
console.log("Finished");

CALL STACK / LAST IN, FIRST OUT

script()
Console is empty

01 / 14Start script

03

Live example

Predict the three lines before running. Remove the parentheses from showStatus() and compare what disappears.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022
04

Guided challenge

Make the function run

The console skips Ready. Change the function reference into a call.

Opening editor…
LIVE PREVIEW
Console 0

Your console output appears here.

Saved on this deviceJavaScript · ES2022

EXPECTED CONSOLE OUTPUT

Starting
Ready
Finished

Hints 0/2

    Use all hints or make 3 failed runs (0/3).

    05

    Free sandbox

    Make a variation, test an assumption, or break the example on purpose. This draft is saved separately.

    Opening editor…
    LIVE PREVIEW
    Console 0

    Your console output appears here.

    Saved on this deviceJavaScript · ES2022
    06

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01When does the body of showStatus run?
    02Who provides document in a browser?

    Ready to call this one understood?

    Mark this lesson complete to earn 100 XP. You can always revisit it.

    Sign in to save progress
    Next lesson