DEV Community

Discussion on: How long does it take to learn to code?

Collapse
 
pengeszikra profile image
Peter Vivo
const dateList = [];

function recordDate(date) {
    dateList.push(date);
}

function displayDates() {
    console.log(dateList);
}
Enter fullscreen mode Exit fullscreen mode

The problem with this code piece are recordDate and displayDates have outer dependency: dateList. Without that variable these two function is useless.

Collapse
 
jamesthomson profile image
James Thomson

100%. Much better to use pure functions.

Collapse
 
rafarochas91 profile image
Rafael Rocha

Or provide the dependency as a parameter even if it contains side effects you have overall control. Following the Inversion of Control principle.

Collapse
 
dakujem profile image
Andrej Rypo

You would export the functions from the module and keep the variable private. It's not the point of the example.

Collapse
 
coderslang profile image
Coderslang: Become a Software Engineer

I absolutely agree. And it's another proof of the fact that learning never stops 🚀