University of Sydney · FACULTY OF COMPUTER SCIENCE

IDEA9103 Chap.5 JavaScript Execution and Statements

- one subject, every graph, every model, every mark
6 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 5 of 10 · IDEA9103

JavaScript Execution and Statements

JavaScript adds behaviour to the page through evaluated expressions and executed statements. The console supports short experiments and debugging, while a linked script keeps project behaviour maintainable. This chapter follows browser load order, distinguishes a produced value from a stored effect, and uses an earliest failure ladder to separate missing files, missing nodes and wrong data.

In this chapter

What this chapter covers

  • 01

    Browser console

  • 02

    Inline scripts

  • 03

    Linked JavaScript files

  • 04

    Parse and load order

  • 05

    Expressions and statements

  • 06

    Boundary based debugging

Worked example · free

Trace an unused expression

Q [4 marks]. The practice mark allocation used here is not part of the University's published assessment scheme. Start size at 12, evaluate size times three without assignment, then assign size plus five and log size.
The arrows show the browser building document nodes before JavaScript evaluates statements and changes the visible page state.The arrows show the browser building document nodes before JavaScript evaluates statements and changes the visible page state.Parse documentcreate nodesRun scriptevaluate statementsUpdate pageobserve state
The arrows show the browser building document nodes before JavaScript evaluates statements and changes the visible page state.
  • 1Declaration stores 12.
  • 1Multiplication evaluates to 36 but is not stored.
  • 1Assignment stores 17.
  • 1The console logs 17.
The logged value is 17 because the multiplication result had no assignment or consuming call.
Sia tip — Ask whether an expression's result is stored, returned or passed onward. A calculated value can otherwise disappear immediately.
Glossary

Key terms

Console
A browser tool for evaluating JavaScript and inspecting logged runtime values.
Expression
Code that evaluates to a value.
Statement
An executable instruction that may evaluate expressions and cause an effect.
Script file
A separate JavaScript resource linked from the HTML document.
Parse order
The sequence in which the browser reads source and constructs or executes its parts.
FAQ

JavaScript Execution and Statements FAQ

Why place a script near the end of the body?

The browser reads the document in order. Loading behaviour after the relevant HTML makes those nodes available for selection and avoids delaying content that has not yet been parsed.

When should I use the browser console?

Use it to test a small expression, inspect a type or log current state during debugging. Maintained project behaviour belongs in a linked script rather than in temporary console history.

Why can correct arithmetic produce no visible change?

Evaluation alone does not alter the page. The result must be assigned, passed to a mutating method or used while creating a visible node before the browser output can change.

How can I tell whether a script file loaded?

Inspect the resource request and add one temporary labelled startup log at the beginning of the file. If the request fails, repair the path. If the message appears, move to selector and value checks. Remove the probe after the boundary is understood so routine output remains readable.

What is the difference between a returned value and a side effect?

A returned value travels back to the surrounding expression or caller. A side effect changes external state, such as logging text or mutating an element attribute. Some calls can do both, so the trace should state where evidence will appear rather than assuming every useful result is stored.

Why can an error appear one line after its cause?

An unclosed quote, bracket or parenthesis can leave the parser waiting for completion until it reaches later code that no longer fits. Inspect the preceding statement as well as the highlighted location, and check paired delimiters before rewriting a line whose syntax may actually be valid.

How do I isolate a calculation from a DOM problem?

Temporarily replace the computed value with one known visible literal while keeping selection and mutation unchanged. If the literal appears, the document path works and the calculation needs inspection. If it does not, keep investigating loading, selection, timing or presentation before restoring the original expression.

What makes an execution trace convincing?

Write statements in the order the runtime encounters them and record the value of each relevant binding immediately after a statement completes. Distinguish an expression that merely produces a value from an assignment that changes stored state. Include console output at the precise observation point and identify any statement that cannot execute because an earlier error stops the script.

Finally, rerun the trace with one changed input and predict the first value that should differ. Agreement at that boundary supports the explanation more strongly than matching only the final screen.

Study strategy

Assessment move

Practise the same short operation in the console and in a linked file, then explain the different purpose of each route. Trace whether every expression is consumed. For an inactive page, test the file request, script start, selected node, computed value and visible mutation in that order. Make only one repair after locating the earliest failed boundary.

Working through JavaScript Execution and Statements in IDEA9103? Sia is AskSia’s AI Computer Science tutor — ask any IDEA9103 JavaScript Execution and Statements question and get a clear, step-by-step explanation grounded in how IDEA9103 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

A+Everything unlocked
Unlocks this Bible + all 202 of your University of Sydney subjects - and 1,000+ Bibles across every Australian university.
Sia - your IDEA9103 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works