Client-Side Scripting (JavaScript)
What the exam tests
Variables and data types, functions, conditionals and loops, arrays and objects, DOM selection and events, and simple form validation.
Core rules
- Prefer const; use let when reassigning; avoid var because of function scope and hoisting quirks.
- === compares value and type; == performs coercion.
- Functions can be declarations, expressions or arrow functions.
- DOM: document.getElementById, querySelector, textContent, classList, addEventListener.
- Events: click, submit, input, change. Use event.preventDefault() to stop default form submission when validating.
- JSON.parse and JSON.stringify convert between JSON text and objects.
Worked example
const form = document.querySelector('#signup'); form.addEventListener('submit', (e) => { const email = document.querySelector('#email').value.trim(); if (!email.includes('@')) { e.preventDefault(); document.querySelector('#msg').textContent = 'Enter a valid email'; } }); Reasoning: the submit handler reads the trimmed value, checks for @, blocks submission only on failure, and writes a message into the page. This is client-side validation; server-side validation is still required.
Traps
Do not use = in an if condition. Do not run DOM code before the document loads unless you defer the script. Do not treat '5' + 1 as 6. Do not rely on client-side validation alone. Remember .value is for inputs, .textContent for elements.