Imperative programming versus declarative programming

Imperative programming is made up of statements that help change the program's state. As mentioned before, it focuses on the how rather than the what. Let's have a look at what this can look like in code to make it more clear:

let sum = 0;function updateSum(records) {  for( let i = 0; i< records.length; i++ ) {    sum += records[i];   }}updateSum([1,2,3,4]);

The preceding code has the following effect: the variable sum is updated when we call updateSum().  We can also see that the function is very explicit about how the summation should happen.

Declarative programming is more focused on what to achieve. It's easy to think of this as being more high-level, because you say what you want to achieve. ...

Get Architecting Angular Applications with Redux, RxJS, and NgRx 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.