Search⌘ K
AI Features

Solution Review: Check the Names

Understand how to implement asynchronous callback functions that validate first and last names. Learn to handle errors when names are missing and how to return combined names using callbacks in JavaScript.

We'll cover the following...

Solution

Javascript (babel-node)
const checkName = (firstName, lastName, callback) => {
if (!firstName) return callback(new Error('No First Name Entered'))
if(!lastName) return callback(firstName)
const fullName = `${firstName}` + `${lastName}`
return callback(fullName)
}
function callback(arg){
console.log(arg)
}

Explanation

...