Note: This article is purely for obtaining script tokens. Any apps which need to log users in, or use a redirect URI, I would recommend passport-reddit

I recently found myself in a position where I had to access reddit's api manually in Javascript, but couldn't find any examples where this was done with Javascript (though, if you have the ability, I would recommend using a wrapper like snoowrap). So, the hope is that this serves as a good example.

The first task is obtaining all the necessary information. This would mean getting a username, password, app_client_id, and app_client_secret. If you haven't made an app on reddit to obtain the client_id and client_secret, you can do that by going to 'preferences', then 'apps'.

After obtaining all of that, the code below will obtain an access_token when run. This uses the package request to make the POST request, but the standard 'http' library will suffice as well. (Also, you shouln't be using this on the front-end because the client_secret is meant to be secret)
var buffer = new Buffer(app_client_id + ':' + app_client_secret).toString('base64')
var auth = 'Basic ' + buffer

var options = {
  url: 'https://www.reddit.com/api/v1/access_token',
  form: {
    "grant_type": "password",
    "username": reddit_username,
    "password": reddit_password
  },
  headers: {
    'Authorization': auth,
    'User-Agent': '<YOUR USER AGENT HERE>'
  }
}

request.post(options, (error, response, body) => {
  if (error) {
    reject(error)
  }
  var access_token = JSON.parse(body).access_token
}
Now we have an access token! And finally, we can use that access_token in a request to the API. This is a simple example of that kind of call (this is also using the 'request' module).
var options = {
  url: 'https://oauth.reddit.com/api/v1/me', // the endpoint to hit

  headers: {
    'Authorization': 'bearer <YOUR ACCESS TOKEN>',
    'User-Agent': '<YOUR USER AGENT HERE>'
  }
}
  
request(options, (error, response, body) => {
  if (error) {
    console.log('Error:', error)
  }
  
  body = JSON.parse(body)
})