Saving changes made using functions

Hello,

This is a big picture question. I am learning javascript and doing well, but sometimes when I am writing out the code, I fail to see how what I’m doing is useful if I navigate away from the page. In other words, were the practice exercises to go live on an app or website, any changes that I made to arrays or variables would go away. I assume that at some point I will learn how databases interact with javascript, since that is where I assume my function parameters will feed to “in the real world.” I am aware that I have a huge gap in my knowledge, I am just trying to get a slightly clearer big picture view.

1 Like

JavaScript – as far as for coding websites / apps – is a client-side scripting language.

Your app’s / website’s database is on a server – thus the ‘classic’ answer would be that javascript can’t access it directly (though that’s not the same as saying it can’t be done).

So I think the answer would be that you’d typically be making API calls to either your own web app’s backend, or to fetch data from another service’s API (e.g. fetching tweets from twitter, or stock data from a trading API).

If you needed to access data from a database in your own web app, you’d be creating an API for your own app using PHP Laravel, or Express.js for Node.js, or some other server-side technology; your API methods would pass JSON objects to your front-end JavaScript code.

1 Like