My goal is to predict what is the value of 2020 if the growth remains the same. The problem was given as how a population of particular artificial country will grow so I am not sure if the exponential model describes the growth well enough.
Do you mean, how do you write a linear regression formula, or how do you verify that the historical population figures for a country do show exponential growth?
Can you work out the logarithms of those numbers and do regression on them? If you were doubling those numbers every ten years, you would have reached 6,400,000 by now.
You mentioned JS, which we already have a forum for, but I think I should add you to our general computing forum because such algorithms are language‑neutral.
The three important things are Matrix multiplication, transpose a Matrix and invert a Matrix. Look for Gaussian elimination for the inversion. I always used Excel too, to see graphically what kind of model I had to use (direct lineat, log-log, quadratic, et cetera.
Another way is to look up the formulas that involve terms line x, x^2, x*y, y^2 et cetera, no linear algebra required.
I have this method in my Matrix class: (it's in java)
There are three kinds of actuaries: those who can count, and those who can't.