LPI Web Dev Essentials study materials
LPI Web Dev Essentials study resources

LPI Web Dev Essentials: JavaScript Programming

LPI Web Dev Essentials · Work through your exam, one topic at a time.

All guide sections

JavaScript Programming

JavaScript Programming covers the language itself plus browser interaction. Questions test value types and coercion, scope, functions, array and object methods, DOM events, and asynchronous code.

Values, scope, and operators

  • const and let are block-scoped; var is function-scoped and hoisted as undefined.
  • === compares without coercion; == converts types, so "5" == 5 is true.
  • Falsy values are false, 0, "", null, undefined, and NaN.

Functions and objects

  • Function declarations hoist; function expressions and arrow functions do not.
  • Arrow functions do not bind their own this.
  • Closures let a function retain access to variables from its defining scope.

DOM, events, and async

  • Use document.querySelector(), addEventListener(), and event.preventDefault() to control the page.
  • A promise is pending, fulfilled, or rejected; async/await makes asynchronous code read sequentially, and await calls belong in try/catch.

Worked example

const prices = [10, 25, 5];
const total = prices
  .filter(p => p > 5)
  .map(p => p * 2)
  .reduce((sum, p) => sum + p, 0);

Reasoning: filter keeps [10, 25]; map produces [20, 50]; reduce starts from 0 and returns 70. Each method returns a new array except reduce, so prices is unchanged - a common exam point.

Traps

Mutating an object held in a const is allowed, because the binding is constant, not the contents. Remember that NaN !== NaN, that await only works inside an async function, and that this inside a setTimeout callback is not the surrounding object. Forgetting return in an arrow function with braces silently yields undefined.