- Single quotes for strings by default, for consistency with most JavaScript styles:
- Single quotes for strings by default, for consistency with most JavaScript styles:
```
```javascript
"bad"// Bad
"bad"// Bad
'good'// Good
'good'// Good
```
```
- Use parentheses or `\`` instead of '\\' for line continuation where ever possible
- Use parentheses or `\`` instead of '\\' for line continuation where ever possible
- Open braces on the same line (consistent with Node):
- Open braces on the same line (consistent with Node):
```
```javascript
if (x){
if (x){
console.log("I am a fish");// Good
console.log("I am a fish");// Good
}
}
...
@@ -56,7 +56,7 @@ General Style
...
@@ -56,7 +56,7 @@ General Style
```
```
- Spaces after `if`, `for`, `else` etc, no space around the condition:
- Spaces after `if`, `for`, `else` etc, no space around the condition:
```
```javascript
if (x){
if (x){
console.log("I am a fish");// Good
console.log("I am a fish");// Good
}
}
...
@@ -73,7 +73,7 @@ General Style
...
@@ -73,7 +73,7 @@ General Style
are simple and closely related. If you put the next declaration on a new line,
are simple and closely related. If you put the next declaration on a new line,
treat yourself to another `var`:
treat yourself to another `var`:
```
```javascript
varkey="foo",
varkey="foo",
comparator=function(x,y){
comparator=function(x,y){
returnx-y;
returnx-y;
...
@@ -91,7 +91,7 @@ General Style
...
@@ -91,7 +91,7 @@ General Style
```
```
- A single line `if` is fine, all others have braces. This prevents errors when adding to the code.:
- A single line `if` is fine, all others have braces. This prevents errors when adding to the code.:
```
```javascript
if (x)returntrue;// Fine
if (x)returntrue;// Fine
if (x){
if (x){
...
@@ -103,7 +103,7 @@ General Style
...
@@ -103,7 +103,7 @@ General Style
```
```
- Terminate all multi-line lists, object literals, imports and ideally function calls with commas (if using a transpiler). Note that trailing function commas require explicit configuration in babel at time of writing:
- Terminate all multi-line lists, object literals, imports and ideally function calls with commas (if using a transpiler). Note that trailing function commas require explicit configuration in babel at time of writing:
```
```javascript
varmascots=[
varmascots=[
"Patrick",
"Patrick",
"Shirley",
"Shirley",
...
@@ -125,7 +125,7 @@ General Style
...
@@ -125,7 +125,7 @@ General Style
When something is intentionally missing or removed, set it to null.
When something is intentionally missing or removed, set it to null.