():
JavaScript
:
if (condition) {
// do this
// ...and that
// ...and that
}
if (condition) doSomething()
:
- ! :
if (n < 0) {alert(`Power ${n} is not supported`);} - :
if (n < 0) alert(`Power ${n} is not supported`); - 1:
if (n < 0) alert(`Power ${n} is not supported`); - :
if (n < 0) { alert(`Power ${n} is not supported`); }
if (cond) return null
:
// `
let str = `
ECMA International's TC39 is a group of JavaScript developers,
implementers, academics, and more, collaborating with the community
to maintain and evolve the definition of JavaScript.
`;
if :
if (
id === 123 &&
moonPhase === 'Waning Gibbous' &&
zodiacSign === 'Libra'
) {
letTheSorceryBegin();
}
1 80 120
:
-
2(4)
2 4 ( Tab)
:
show(parameters, aligned, // 5 one, after, another ) { // ... } -
:
:
function pow(x, n) { let result = 1; // <-- for (let i = 0; i < n; i++) { result *= x; } // <-- return result; }9
JavaScript StandardJS
if :
for (let i = 0; i < 10; i++) {
if (cond) {
... // <- 1
}
}
:
for (let i = 0; i < 10; i++) {
if (!cond) continue;
... // <-
}
if/else return
2
:
function pow(x, n) {
if (n < 0) {
alert("Negative 'n' not supported");
} else {
let result = 1;
for (let i = 0; i < n; i++) {
result *= x;
}
return result;
}
}
2:
function pow(x, n) {
if (n < 0) {
alert("Negative 'n' not supported");
return;
}
let result = 1;
for (let i = 0; i < n; i++) {
result *= x;
}
return result;
}
2n < 0
3
-
:
// function createElement() { ... } function setHandler(elem) { ... } function walkAround() { ... } // let elem = createElement(); setHandler(elem); walkAround(); -
// let elem = createElement(); setHandler(elem); walkAround(); // --- --- function createElement() { ... } function setHandler(elem) { ... } function walkAround() { ... } -
:
2
:
1
:
linter
Linter
:
linter :
ESLint :
- Node.js
npm install -g eslintESLint (npm Node.js )- JavaScript()
.eslintrc - ESlint /
.eslintrc :
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"no-console": 0,
"indent": 2
}
}
"extends" eslint:recommended
ESLint /
Webhttp://eslint.org/docs/user-guide/getting-started
linter : linter linter ()
linter
IDE linter ESLint
<code><pre>10(plnkr, JSBin, codepen)