Frequently Asked Questions

that I always come across


Project maintained by Phoenix35 Hosted on GitHub Pages — Theme by mattgraham

I want to develop a discord bot.

If you are just beginning in JS, only some parts of The Modern JavaScript tutorial are required:

As well as 2 primers on events, and Websocket

Now you’re ready to learn using the only valid discord.js bot tutorial, you’re welcome.

I want to learn front-end. Where would I start?

Make sure you are at least intermediate in JavaScript (see Resources). Learn some HTML/CSS.

Expand your skills with network, SEO, accessibility, APIs, etc….

Feel free to contribute any resources

Angular, React, Vue, others?

React. Don’t learn Angular if you don’t have to.
Until React Suspense is a thing, use React Async.

To learn the trade for future jobs? It depends entirely on your market. If you don’t know, I would go for React this time, as it’s the least opinionated.
But look the stack used by companies in the area you want to apply, this will be a far better gauge.

How to begin in JS?

JS.info is currently the best online resource out there to learn modern JS and some frontend, but mandatory entries are mixed with optional knowledge. Here’s what you should take out of js.info

Part 1

Part 2

Even if you won’t work with the browser, there are concepts revelant for all environments

If browser environment: 5.2 Scripts: async, defer see related correct use of JS in the browser; the entirety of Part 2

Part 3

What license?

WE ARE NOT LAWYERS
However, to get a feeling of what you can and cannot do with a third party program, it’s published with a certain license
https://tldrlegal.com/
To find out your own https://choosealicense.com/

I cannot build a package on Windows

You’re on Windows and a package that has a build step (node-canvas, bson, sqlite3, etc…) outputs an error with a trace like
node-pre-gyp ERR! build error
?
You need specific build tools on Windows that don’t come natively and that node-gyp failed to install by itself.

Here are the quick steps to solve this:

  1. Install python (Python 3.9.6 at the time of writing)
  2. You will now have to do some commands. From an elevated terminal (so with admin rights)
    npm i -g --production windows-build-tools --vs2015
    Don’t worry, it’s the official build tools
  3. When installed (it may take a while), from the same elevated prompt
    npm config set msvs_version 2015
  4. where python
    Copy the resulting path and use it in the next command
  5. npm config set python C:\\Python39\\python.exe (or your actual path, you get it)

Only do these steps this one time and you shouldn’t have anymore problems

Basics of NPM

  1. https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
  2. https://docs.npmjs.com/packages-and-modules/getting-packages-from-the-registry
  3. https://docs.npmjs.com/cli/v8/commands/npx
  4. https://docs.npmjs.com/cli/v8/using-npm/developers
  5. https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry

Relevant info on a package page https://imgur.com/PQJiC0G

Check if its license matches your needs (see What license?)

A small list of bad packages and their alternatives

From promises to async functions

(WIP) By example

function fetchJSON (url) {
  return fetch(url).then(response => response.json());
}

function updatePara (url) {
  fetchJSON(url).then(data => {
    const { title, text }  = data;

    paragraph.dataset.title = title;
    paragraph.textContent = text;
  })
  .catch(log);
}
async function fetchJSON (url) {
  const response = await fetch(url);

  return response.json();
}

async function updatePara (url) { // You obviously NEED the async keyword
  try {
    const { title, text } = await fetchJSON(url);

    paragraph.dataset.title = title;
    paragraph.textContent = text;
  } catch (err) {
    log(err);
  }
}

https://2ality.com/2016/10/async-function-tips.html

var? const? let?

var was the old way of declaring variables. Its features can and do lead to confusion, so just don’t use it.

ES6 introduced const and let. They are the sane way of declaring variables.
Your editor will tell you are writing code that cannot run, so your code will become less ugly by force.
As to which between const and let? Use const always. Refer to best practices.

By using const, you’re stating: “This variable will only allowed to be an Enum (constant string, magic number, config boolean) or a collection (array, object, set, map) and nothing else, my linter will tell me if I screw up when I use it in any other way”.
Moreover, if you default to const, then let conveys more meaning: “This variable MUST change in the flow of my program (concatenate strings, add numbers, toggle a boolean dynamically, allow this object to be emptied again or extending it via spread)”.

An added benefit of const is that let doesn’t allow for constant folding.

I’m using forEach to…

Don’t.