Back to the full dot-point answer
NSWSoftware EngineeringQuick questions
Module 2: Programming for the Web
Quick questions on JavaScript in the browser explained: HSC Software Engineering Module 2
13short Q&A pairs drawn directly from our worked dot-point answer. For full context and worked exam questions, read the parent dot-point page.
What is selecting elements (DOM access)?Show answer
The DOM (Document Object Model) is a tree representation of the HTML document. JavaScript reads and modifies it through methods like:
What is modifying the DOM?Show answer
const newItem = document.createElement("li"); newItem.textContent = "New point"; document.querySelector("ul").appendChild(newItem);
What is events?Show answer
JavaScript responds to user actions through event listeners:
What is asynchronous requests?Show answer
Browser JavaScript exchanges data with the server through the fetch API, which returns a Promise that resolves with the response. Combined with async and await, this lets you write asynchronous code that reads like synchronous code, with try/catch for error handling.
What is putting it together?Show answer
A complete example - a search-as-you-type input:
What is variables, types, control flow?Show answer
const numbers = [1, 2, 3, 4]; const doubled = numbers.map(n => n * 2); // [2, 4, 6, 8] const even = numbers.filter(n => n % 2 === 0); // [2, 4] const sum = numbers.reduce((acc, n) => acc + n, 0); // 10
What is security?Show answer
Setting innerHTML with a value that came from user input is one of the most common ways an XSS vulnerability slips into a front-end. The browser parses the assigned string as HTML, so any script tag, event handler attribute, or javascript URL inside it can execute. Use textContent or the DOM API instead.
What is bug 1?Show answer
the handler does not receive the event, so it cannot call event.preventDefault(). The form submits even when validation fails, because the browser's default submit fires alongside the JavaScript handler.
What is bug 2?Show answer
innerHTML is used to insert text. If the error string ever contains user-controlled data, this is an XSS risk. Use textContent.
What is forgetting event.preventDefault on form submit handlers?Show answer
Without it the browser navigates to the form's action URL and your JavaScript handling is lost.
What is mixing = and == and ===?Show answer
Use === (strict equality) by default. == does type coercion with surprising results ("" == 0 is true).
What is blocking the main thread?Show answer
Long synchronous loops freeze the page. Use async/await for I/O, and consider Web Workers for heavy computation.
What is trusting client-side validation?Show answer
Always re-validate on the server. JavaScript can be disabled or bypassed. :::