JavaScript

Resources

Type

MDN

Array

MDN

Date

MDN

Object

MDN

String

MDN

JSON

MDN

Set

MDN

RegExp

MDN

Destructuring Assignment

MDN

const

MDN

let

MDN

export

MDN

strict mode

Begin files with:

'use strict';

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode

Arrow functions: () => {}

const a = (param1, param2) => {
return param1 + param2;
}
const b = (param1, param2) => param1 + param2;

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

String

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

UTF Support

https://stackoverflow.com/questions/16293923/does-v8-have-unicode-support https://github.com/v8/v8/blob/master/include/v8.h

Async

async () => {
await new Promise(...);
const [
result1,
result2,
] = await Promise.all([
new Promise(),
new Promise(...)],
);
return value;
}

Promises

When you start chaining a lot of promises and passing variables around, consider usings aysnc instead.

Pay attention to the style, because it's really stupid.

const start = new Promise((resolve, reject) => {
xhr.get(url)
.success((result) => resolve(result))
.failure((error) => reject(error));
});
const afterStart = (startResult) => new Promise((resolve, reject) => {
});
start
.then(afterStart)
// Always start on a new line, its easier to catch
// Always use a Promise or only { Promise.all([]) }, its eaiser to catch
.then() => new Promise((resolve, reject) => {
})
.catch((error) => {
console.log(error);
});
  • Always have a catch() to ensure you can see all errors.

window

window.location.hash

console.log(window.location.hash);

Results:

#array

Results will always be prefixed with #

scroll

Scroll to a part of the screen.

window.location.hash = '#object'

trailing commas

http://exploringjs.com/es2016-es2017/ch_trailing-comma-parameters.html

Simple Assert

input = "a b c d e";
main(input) {
...
}
assert(expected, input) {
console.log(input);
actual = main(input);
result = expected === actual;
console.log(result);
if (!result) {
console.log(actual);
console.log(expected);
}
}
// Case 1
assert(expected, input);
// Case 2
assert(expected2, input2);
// Case 3
assert(expected3, input3);

Warning: querystring.stringify does not stringify deeply nested objects.

Classes

class Animal {
constructor() {
}
}
class Cat extends Animal {
constructor(props) {
super(props)
}
}

Flow vs TypeScript

Flow

https://flow.org/en/docs/config/

https://github.com/facebook/relay/blob/master/.flowconfig https://github.com/facebook/react/blob/master/.flowconfig https://github.com/graphql/graphql-js/blob/master/.flowconfig

ESLINT

Alternatives

Frameworks

ORM