Callbacks are functions than are invoked as argument to manipulate or propagate the result of an internal operation.
function createUser(fullName) {
const timestamp = Date.now();
const userId = `${Math.floor(Math.random() * 100)}-${timestamp}`;
return {
id: userId,
user: fullName,
createdAt: timestamp,
};
}
function processUserEntry(name, surname, callback) {
if (!name || !surname) return {};
const fullName = `${name} ${surname}`;
const newUser = callback(fullName);
return newUser;
}
processUserEntry("Ada", "Lovelace", createUser);