Imperative versus declarative programming

Imperative programming concerns itself with how something is accomplished, while declarative programming concerns itself with what we want accomplished. It's difficult to see the difference between these so it's best to illustrate them with a simple program:

function getUnpaidInvoices(invoiceProvider) {  const unpaidInvoices = [];  const invoices = invoiceProvider.getInvoices();  for (var i = 0; i < invoices.length; i++) {    if (!invoices[i].isPaid) {      unpaidInvoices.push(invoices[i]);    }  }  return unpaidInvoices;}

This function's problem domain would be: getting unpaid invoices. That is the task the function has and it is what we want to achieve within the function. This particular function, however, ...

Get Clean Code in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.