|
41 | 41 |
|
42 | 42 | ## Types
|
43 | 43 |
|
44 |
| - - **Primitives**: When you access a primitive type you work directly on its value |
| 44 | + - **Primitives**: When you access a primitive type you work directly on its value. |
45 | 45 |
|
46 | 46 | + `string`
|
47 | 47 | + `number`
|
|
57 | 57 |
|
58 | 58 | console.log(foo, bar); // => 1, 9
|
59 | 59 | ```
|
60 |
| - - **Complex**: When you access a complex type you work on a reference to its value |
| 60 | + - **Complex**: When you access a complex type you work on a reference to its value. |
61 | 61 |
|
62 | 62 | + `object`
|
63 | 63 | + `array`
|
|
86 | 86 | var item = {};
|
87 | 87 | ```
|
88 | 88 |
|
89 |
| - - Don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61) |
| 89 | + - Don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). |
90 | 90 |
|
91 | 91 | ```javascript
|
92 | 92 | // bad
|
|
125 | 125 |
|
126 | 126 | ## Arrays
|
127 | 127 |
|
128 |
| - - Use the literal syntax for array creation |
| 128 | + - Use the literal syntax for array creation. |
129 | 129 |
|
130 | 130 | ```javascript
|
131 | 131 | // bad
|
|
178 | 178 |
|
179 | 179 | ## Strings
|
180 | 180 |
|
181 |
| - - Use single quotes `''` for strings |
| 181 | + - Use single quotes `''` for strings. |
182 | 182 |
|
183 | 183 | ```javascript
|
184 | 184 | // bad
|
|
195 | 195 | ```
|
196 | 196 |
|
197 | 197 | - Strings longer than 80 characters should be written across multiple lines using string concatenation.
|
198 |
| - - Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40) |
| 198 | + - Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). |
199 | 199 |
|
200 | 200 | ```javascript
|
201 | 201 | // bad
|
|
557 | 557 | }
|
558 | 558 | ```
|
559 | 559 |
|
560 |
| - - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/) |
| 560 | + - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/). |
561 | 561 |
|
562 | 562 | **[⬆ back to top](#table-of-contents)**
|
563 | 563 |
|
|
606 | 606 | }
|
607 | 607 | ```
|
608 | 608 |
|
609 |
| - - For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll |
| 609 | + - For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. |
610 | 610 |
|
611 | 611 | **[⬆ back to top](#table-of-contents)**
|
612 | 612 |
|
|
706 | 706 |
|
707 | 707 | - Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.
|
708 | 708 |
|
709 |
| - - Use `// FIXME:` to annotate problems |
| 709 | + - Use `// FIXME:` to annotate problems. |
710 | 710 |
|
711 | 711 | ```javascript
|
712 | 712 | function Calculator() {
|
|
718 | 718 | }
|
719 | 719 | ```
|
720 | 720 |
|
721 |
| - - Use `// TODO:` to annotate solutions to problems |
| 721 | + - Use `// TODO:` to annotate solutions to problems. |
722 | 722 |
|
723 | 723 | ```javascript
|
724 | 724 | function Calculator() {
|
|
735 | 735 |
|
736 | 736 | ## Whitespace
|
737 | 737 |
|
738 |
| - - Use soft tabs set to 2 spaces |
| 738 | + - Use soft tabs set to 2 spaces. |
739 | 739 |
|
740 | 740 | ```javascript
|
741 | 741 | // bad
|
|
1042 | 1042 | }
|
1043 | 1043 | ```
|
1044 | 1044 |
|
1045 |
| - - Use camelCase when naming objects, functions, and instances |
| 1045 | + - Use camelCase when naming objects, functions, and instances. |
1046 | 1046 |
|
1047 | 1047 | ```javascript
|
1048 | 1048 | // bad
|
|
1061 | 1061 | });
|
1062 | 1062 | ```
|
1063 | 1063 |
|
1064 |
| - - Use PascalCase when naming constructors or classes |
| 1064 | + - Use PascalCase when naming constructors or classes. |
1065 | 1065 |
|
1066 | 1066 | ```javascript
|
1067 | 1067 | // bad
|
|
1083 | 1083 | });
|
1084 | 1084 | ```
|
1085 | 1085 |
|
1086 |
| - - Use a leading underscore `_` when naming private properties |
| 1086 | + - Use a leading underscore `_` when naming private properties. |
1087 | 1087 |
|
1088 | 1088 | ```javascript
|
1089 | 1089 | // bad
|
|
1143 | 1143 |
|
1144 | 1144 | ## Accessors
|
1145 | 1145 |
|
1146 |
| - - Accessor functions for properties are not required |
1147 |
| - - If you do make accessor functions use getVal() and setVal('hello') |
| 1146 | + - Accessor functions for properties are not required. |
| 1147 | + - If you do make accessor functions use getVal() and setVal('hello'). |
1148 | 1148 |
|
1149 | 1149 | ```javascript
|
1150 | 1150 | // bad
|
|
1160 | 1160 | dragon.setAge(25);
|
1161 | 1161 | ```
|
1162 | 1162 |
|
1163 |
| - - If the property is a boolean, use isVal() or hasVal() |
| 1163 | + - If the property is a boolean, use isVal() or hasVal(). |
1164 | 1164 |
|
1165 | 1165 | ```javascript
|
1166 | 1166 | // bad
|
|
1406 | 1406 |
|
1407 | 1407 | ## ECMAScript 5 Compatibility
|
1408 | 1408 |
|
1409 |
| - - Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/) |
| 1409 | + - Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/). |
1410 | 1410 |
|
1411 | 1411 | **[⬆ back to top](#table-of-contents)**
|
1412 | 1412 |
|
|
0 commit comments