I’m wondering if it is bad practice or if it makes it harder to read if you define constants outside of a function and then pass them into the function as arguments?
const mainFunction = () => {
const x = document.getElementById("example");
y = subFunction1(x);
z = subFunction2(x);
};
const subFunction1 = (x) => {
// do something with x
};
const subFunction2 = (x) => {
// do something else with x
};
I’m defining a constant in mainFunction and passing it into the sub functions. Would this make more sense just being a global constant? I’m in the early stages of learning javascript and I want to make sure I learn the best practices. thanks!
Russell Boeger is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.