Hey Jay, these are great questions- I'll do my best to answer.
First of all, don't look at the getCookie() function first- that's just something I define at the top of my javascript, but it doesn't get used at that point. The function only gets used when it is called later.
To understand where USER_SESSION_TOKEN comes from, I'd suggest you take another look at this schema: https://lucid.app/publicSegments/view/9d0ddbcb-f89f-4551-8970-a6d45dd3a803/image.jpeg
As you can see, token = id_token. If you look at the corresponding code, (Section 8.1; search for //SIGN IN/SIGN UP: SET COOKIE VALUE IN BROWSER)
you'll see id_token gets created from googleUser.getAuthResponse(). This function is a Google function that I used and it basically gets triggered when you see that Google 'sign in' box that pops up.
Now go back to the schema linked above. To follow the logic you need to jump to the BackEnd, on the route /SignIn. Here we use another function (that's also defined at the top of this file), which takes the token you just created via Google and verifies() it. As you can see in the schema, if the token is successfully verified by our verify() function, then the cookie USER_SESSION_TOKEN is created with the value set to token (which is the same as id_token, above).
I know that might be hard to follow, so I'd encourage you to study the schemas I've drawn, it's really all there.
----
On separating out the javascript: This is probably because you're running everything on your localhost server. Express is the tool we use to do that in this case and Express looks for things like javascript files in a folder called 'public' (don't as me why, but that's what it's called and that's what you have to call it).
I didn't use a 'public' folder in this guide, so you'll need to create one in the same directory and then make sure your path is correct in the script tags when you load in this file. I'm sure you can Google this if it's not 100%.
And yes, basically we're storing it as variable in order to export it. To be honest, I'm hazy myself on what precisely is going on here (as I've mentioned I'm also learning this stuff), but I think you've got the gist.
Hope that helps!