I am trying to run some code that refreshes the webpage, and THEN does the console log.
The issue is the console.log is happening before the page reload.
location.reload();
console.log("test");
How do I adjust this to get the desired behavior?
The very act of refreshing a web page ends execution of scripts on that page, apart from what might be called in onbeforeunload or onunload handlers. Once the reload has actually occurred, no more JavaScript in the pre-reload page can be executed.
If you need to cause something to happen after content has been reloaded, you'll have to use something like a cookie to pass a message to the reloaded page indicating the action you want to take.
setTimeoutwill be cleared and no longer exists unfortunately. As for options, it depends on if you have access to a backend (or server side). Then you could have the ability to send a response and then then on the reload the server would be able to send a response with the value string. With only client-side, as @kshetline said, you would need a cookie to pass messages between reloaded pages.