Skip to content

Commit a17a260

Browse files
authored
Update javascript.md (#37)
1 parent 6071c1e commit a17a260

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

languages/javascript.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Projects should use both [JSHint] and [ESLint] to enforce these rules.
1515
- [Indentation](#indentation)
1616
- [White Space](#white-space)
1717
- [Semi-Colons](#semi-colons)
18+
- [Variables](#variables)
1819
- [Client-Side JavaScript Architecture](#client-side-javascript-architecture)
1920
- [Directory Structure](#directory-structure)
2021
- [Components Directory](#components-directory)
@@ -200,6 +201,34 @@ var baz = function() {
200201
}
201202
```
202203

204+
### Variables
205+
206+
We define variables with multiple `var` statements and trust our developers to understand [hoisting]. We generally discourage defining variables inside loops or blocks.
207+
208+
We do this:
209+
210+
```js
211+
var foo = 1;
212+
var bar = 2;
213+
214+
var baz;
215+
if (foo === bar) {
216+
baz = 3;
217+
}
218+
```
219+
220+
We _don't_ do this:
221+
222+
```js
223+
var foo = 1,
224+
bar = 2;
225+
226+
if (foo === bar) {
227+
var baz = 3;
228+
}
229+
```
230+
231+
203232
Client-Side JavaScript Architecture
204233
-----------------------------------
205234

@@ -272,4 +301,5 @@ An example utility might be a function to make a string title-case.
272301
[complexity]: https://en.wikipedia.org/wiki/Cyclomatic_complexity
273302
[eslint]: http://eslint.org/
274303
[jshint]: http://jshint.com/
304+
[hoisting]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#var_hoisting
275305

0 commit comments

Comments
 (0)