Preparing your workspace
Validation checks whether data is acceptable, transformation changes its representation, and normalization makes data consistent and easier to process.
Data coming from users, APIs, files, or external services should not be trusted blindly. Validation checks requirements such as required fields, data types, ranges, and allowed values. Transformation converts data into the format the application expects, such as turning a string into a number. Normalization can also standardize values, such as consistent casing, whitespace, or date representation. These steps reduce errors and make application logic more predictable.
A registration form may receive a name with extra spaces and an age as text. The server validates the fields and converts them into the expected format before storing them.
const input = {
name: " Aman ",
age: "20"
};
const name = input.name.trim();
const age = Number(input.age);
if (!name || !Number.isInteger(age)) {
throw new Error("Invalid data");
}
console.log({ name, age });{ name: 'Aman', age: 20 }