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. ...