From 2ac3371ea4aec331898c459e33384187d725d285 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Thu, 18 May 2017 22:51:22 +0100 Subject: [PATCH 1/2] Don't suggest vars!! --- code_style.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/code_style.md b/code_style.md index f0eca75ffc..29e54057f8 100644 --- a/code_style.md +++ b/code_style.md @@ -74,20 +74,20 @@ General Style treat yourself to another `var`: ```javascript - var key = "foo", + const key = "foo", comparator = function(x, y) { return x - y; }; // Bad - var key = "foo"; - var comparator = function(x, y) { + const key = "foo"; + const comparator = function(x, y) { return x - y; }; // Good - var x = 0, y = 0; // Fine + let x = 0, y = 0; // Fine - var x = 0; - var y = 0; // Also fine + let x = 0; + let y = 0; // Also fine ``` - A single line `if` is fine, all others have braces. This prevents errors when adding to the code.: From 73d68c551303e03404f4d300c62ddf820cd7f0ff Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@googlemail.com> Date: Thu, 18 May 2017 23:03:34 +0100 Subject: [PATCH 2/2] no leading lines for else,finally,catch etc --- code_style.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/code_style.md b/code_style.md index 29e54057f8..2cac303e54 100644 --- a/code_style.md +++ b/code_style.md @@ -69,6 +69,22 @@ General Style console.log("I am a fish"); // Bad } ``` +- No new line before else, catch, finally, etc: + + ```javascript + if (x) { + console.log("I am a fish"); + } else { + console.log("I am a chimp"); // Good + } + + if (x) { + console.log("I am a fish"); + } + else { + console.log("I am a chimp"); // Bad + } + ``` - Declare one variable per var statement (consistent with Node). Unless they are simple and closely related. If you put the next declaration on a new line, treat yourself to another `var`: