5-min frontend part-2
const createMember = ({ email, address = {}}) => {
const validEmail = /.+\@.+\..+/.test(email)
if (!validEmail) throw new Error("Valid email pls")
return {
email,
address: address ? address : null
}
}
const member = createMember({ email: "my@email.com" })
console.log(member)
Answer is C { email: "my@email.com", address: {} }
Let's understand why , when i am passing email as parameter in createMember function i haven't passed address right but by default it is empty object and in JS empty object means truthy value that reason when it returning i am getting an object which has email and address which is an empty object in it
Thanks and have a great day ahead