Factory Functions & Singleton Pattern

What advantage does this factory function provide?
function createUser(name, email) {
  function validateEmail(email) {
    const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return regex.test(email);
  }
  
  if (!name) throw new Error('Name is required');
  if (!email || !validateEmail(email)) throw new Error('Valid email is required');
  
  return {
    name,
    email,
    createdAt: new Date()
  };
}
Next Question (32/32)