Code Refactor tips

Code Refactor - Better way to write

				
					const sendEmail = (to, subject, body) => {
  if (to) {
    //send email
  } else {
    //some error message
  }
};
//chances of sending wrong value is more as below .
//we are sending email address in subject....
sendEmail("teaching js", "anurag.nayak@hotmail.com", "still novice");
bject: "still novice",
});
				
			
				
					
//Refactored Code
const refactoredSendEmail = ({ to, subject, body }) => {
  if (!to) {
    //error message
  }
  //sendEmail
};
refactoredSendEmail({
  body: "improvement",
  to: "anurag.nayak@hotmail.com",
  subject: "still novice",
});
				
			

Leave a Comment