DEV Community

Discussion on: 8 techniques to write cleaner JavaScript code

Collapse
 
robertrynard profile image
Robert-Rynard

For default object values is there a reason you are spreading out the two objects. Is there an advantage over doing

const createButton = (config) => {
    return {
      color: "#dcdcdc",
      disabled: false,
      title: "",
      padding: 0,
      ...config
    };
}
Enter fullscreen mode Exit fullscreen mode

or using the default values in the arguments?

const createButton = ({ title = "", color = "#333", disabled = false, padding = 0 }) => {
  return {
      title,
      color,
      disabled,
      padding
  };
};
Enter fullscreen mode Exit fullscreen mode