Skip to main content
Module 8 · Lesson 3 of 431/32 in the course~21 min
Module lessons (3/4)

Challenge: data validator

Lesson preview5 hands-on exercises readyJavaScript Course · Module 8 — Practice and composition

Validate objects with composable rules and collect all the errors.

What you'll learn in this lesson

  • Design composable validation rules based on pure functions (data => errorString | null).
  • Collect all errors in a payload rather than stopping at the first bad field.
  • Construct parametric rule factories via closure (required(field), minNumber(field, min)).
  • Avoid exceptions within individual rules so that the pipeline always completes checking all fields.

Overview

A good validator combines higher-order functions, closure factories and array methods (.map, .filter): instead of writing dozens of intertwined ifs and throwing an exception at the first problem, it applies a list of pure rules and collects all errors in a single pass.

Sections covered in this lesson

  1. 1Mental model: composable rules and closure factories
  2. 2Progressive examples
  3. 3Guided laboratory
  4. 4Check for understanding
Pro Lesson · Module 8 — Practice and composition

Unlock "Challenge: data validator" and the full JavaScript Course curriculum

Validate objects with composable rules and collect all the errors.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in JavaScript Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.