Are string saved to arrays permanently saved?

Viewed 90

I'm an 11-year-old learning how to code Javascript, I recently started 1 and a half months ago. I am making a login/register system and am trying to make the register part now. I was wondering if adding a string/number/boolean to an array stays there forever (even after refresh). I would've used cookies for this, but it is not safe.

I am currently using HTML5, CSS3, Javascript, and eventually will be using Jquery. NOTE: The time period does not have to be forever. Does any know the answer to this, please reply? P.S. ( iff you mention PHP for this there would be no point, I don't understand it yet. :/ )

4 Answers

The answer is no. Note that anytime you reload a browser page, your JavaScript also reloads with the page. If you want you data to persist, use a database.

It depends on where you're storing that array. If you want to make a functional login/register on a web-page, you will likely need to use a database such as PostgreSQL.

However, if you want to just create a simple program to run on the command line, the username or password strings you enter in will not remain in memory if you terminate the program. If you terminate your program, it will delete the strings added to your array.

a string or whatever you have in an array will not stay in it forever simply because an array is a data structure which is not persistent. Since you have it in your intention to use more advanced technologies in the near future and you are not comfortable with the cookie because of the obvious security risks. I suggest you use a localStorage to implement the registration feature for your app. Of course you can achieve the same with a sessionStorage, however whatever you save in a sessionStorage will be wiped off when you close the tab which can be handy in the implementation of you login and logout feature for now. Whenever you upgrade the applications to more sophisticated technologies you will have a better way to handle those features.

PS: it might be a little advanced for you right now but when you are more comfortable writing Javascript maybe you will like to checkout IndexDB then NodeJs very much later. #cheers #dontRelent

If you want to create login functionality, you will have to start learning some server-side technologies.

When I was finished (kind of) with learning JavaScript i moved on to NodeJS and MongoDB. NodeJS allows you use JavaScript on the server-side and MongoDB is a database program where you could store data.

Using those two you would create a user model, store it and then check if the user is logged in and etc.

There are many choices to go with when learning back-end, I went with NodeJS because as I already knew JavaScript it was easier to use the same language for the back-end. That and it was part of the Udemy course I had.

Good luck.

Related