You could make your code more readable by using guarding clause in JavaScript. It will avoid nested if ... else statements and makes code cleaner to read in a function.
function exampleFunction(arg) {
if (!arg > someExpressionHere) return;
// ... Do something otherwise
}
In my opinion, a function should only do 1 thing. And it's better than 1 function that do all the work. By splitting up functions in parts, it will make the project more easier to maintain than your current code. Avoid also NESTED functions.
Just write it out in the global scope so other function can reuse it. Or simply use ES6 classes if you like structured code š
Example on nested fns:
function doSomething(arg, arg2) {
// ...
// Nested
function anotherFunction(arg) {
// ... Do something
}
}
Instead:
// Pass in all required args for the function to work
function anotherFunction(arg, arg) {
// ... Do something
}
function doSomething(arg, arg2) {
// ...
// Pass in required arguments
anotherFunction(arg, arg2);
}