Learn JavaScript

JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS.

Companies and DAOs like Streamflow, Alium, PancakeSwap, Findora Foundation, Evmos, Flashbots, Iron Fish, Unstoppable Domains, Nomad and Co:Create use JavaScript to work on Streamflow, AliumSwap, PancakeSwap, Findora, Evmos, Flashbots, Iron Fish, Unstoppable Domains, Nomad and Co:Create.

Conquer the basics of JavaScript here and go pro once you get the hang of it. Average salaries for JavaScript developers are approximately $75k-125k/yr.

Variables are declared like this:

let port = 8333;

If you're not planning on changing a variable, make it a constant:

const port = 8333;

Functions can be created in two ways:

function getPort() {
  return 8333;
}

// this is the same thing as:
const getPort = function() {
  return 8333;
};

Or the shorter arrow format:

const getPort = () => {
  return 8333;
};

// this is the same thing as:
const getPort = () => 8333;

Here's one way to add two numbers:

const add = (one, two) => one + two;
const sum = add(1, 2); // `sum` is now 3

You can create arrays like this:

const ports = [8333, 8334, 8335];

And add to them this way:

ports.push(8336);

By the way did you notice that we've modified a constant by pushing to it?

That still works because you're modifying the contents of the constant. In other words: not re-assigning a completely new value to the constant:

const ports = [8333, 8334];
ports = [8333, 8334, 8335]; // error: assignment to constant variable

This however works:

let ports = [8333, 8334];
ports = [8333, 8334, 8335];

You can loop through arrays like this:

const ports = [8333, 8334, 8335];
for (let i = 0; i != ports.length; i++) {
  console.log("the port is", ports[i]);
}

Or like this:

const ports = [8333, 8334, 8335];
for (const port of ports) {
  console.log("the port is", port);
}

You can use arrays syntax to retrieve values:

const ports = [8333, 8334, 8335];
const [port1, port2, port3] = ports;

port1; // 8333
port2; // 8334
port3; // 8335

And if you don't need all the values, just drop the new variables:

const ports = [8333, 8334, 8335];
const [, port2, ] = ports;

port2; // 8334

Sets let you store unique values of any type:

const s = new Set()
s.add(8333)
s.add(8333)
s.add(8334) // `s` is equal to [8333, 8334]

You can check if a set has a specific value:

s.has(8333); // true

And loop through a set the same way:

const ports = new Set([8333, 8334, 8335]);
for (const port of ports) {
  console.log("the port is", port);
}

You can create objects to store more complex structures:

const bitcoin = {
  name: 'Bitcoin',
  port: 8333,
};

bitcoin.port == 8333; // true

Objects can have functions as properties:

const bitcoin = {
  name: 'Bitcoin',
  port: 8333,
  getNextPort: (port) => port + 1,
};

bitcoin.getNextPort(bitcoin.port) == 8334; // true

You can create a new object from an old one:

const bitcoin = {
  name: 'Bitcoin',
  port: 8333,
};

const newBitcoin = {
  ...bitcoin,
  name: 'New Bitcoin',
};

newBitcoin.name; // New Bitcoin
newBitcoin.port; // 8333
JavaScript: The Good Parts

If you'd like to go beyond the basics, here's a good read:

JavaScript: The Good Parts