function foo() {
∙∙∙∙let name;
}
function bar() {
∙let name;
}
// good
function baz() {
∙∙let name;
}

let luke = {}
let leia = {}
[luke, leia].forEach(jedi => jedi.father = 'vader')
// good
let luke = {};
let leia = {};
[luke, leia].forEach((jedi) => {
});

// 暂时不要编写下面的代码：
//------ lib.js ------
export function square(x) {
return x * x;
}
export function diag(x, y) {
return sqrt(square(x) + square(y));
}
//------ main.js ------
import { square, diag } from 'lib';

{
tiny: 42,
longer: 435,
};
// good
{
tiny: 42,
longer: 435,
};

var example = 42;
// good
const example = 42;

[1, 2, 3].map(function (x) {
const y = x + 1;
return x * y;
});
// good
[1, 2, 3].map((x) => {
const y = x + 1;
return x * y;
});

function sayHi(name) {
return 'How are you, ' + name + '?';
}
function sayHi(name) {
return ['How are you, ', name, '?'].join();
}
function sayHi(name) {
return `How are you, \${ name }?`;
}
// good
function sayHi(name) {
return `How are you, \${name}?`;
}

const longString = 'This is a very long string that \
far exceeds the 80 column limit. It unfortunately \
contains long stretches of spaces due to how the \
continued lines are indented.';
// good
const longString = 'This is a very long string that ' +
'far exceeds the 80 column limit. It does not contain ' +
'long stretches of spaces since the concatenated ' +
'strings are cleaner.';

MDN中有一节专门提到不要使用eval语句。

let obj = { a: 20, b: 30 };
let propName = getPropName(); // returns "a" or "b"
eval( 'var result = obj.' + propName );
// good
let obj = { a: 20, b: 30 };
let propName = getPropName(); // returns "a" or "b"
let result = obj[ propName ]; // obj[ "a" ] is the same as obj.a

const number = 5;
// good
const NUMBER = 5;

let a = 1, b = 2, c = 3;
// good
let a = 1;
let b = 2;
let c = 3;

let directive = "No identification of self or mission."
let saying = 'Say it ain\u0027t so.';
// good
let directive = 'No identification of self or mission.';
// good
let saying = `Say it ain't so`;