* [6.1](https://github.com/yuche/javascript#6.1) 字符串使用单引号 `''` 。
~~~
// bad
const name = "Capt. Janeway";
// good
const name = 'Capt. Janeway';
~~~
* [6.2](https://github.com/yuche/javascript#6.2) 字符串超过 80 个字节应该使用字符串连接号换行。
* [6.3](https://github.com/yuche/javascript#6.3) 注:过度使用字串连接符号可能会对性能造成影响。[jsPerf](http://jsperf.com/ya-string-concat) 和 [讨论](https://github.com/airbnb/javascript/issues/40).
~~~
// bad
const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';
// bad
const errorMessage = 'This is a super long error that was thrown because \
of Batman. When you stop to think about how Batman had anything to do \
with this, you would get nowhere \
fast.';
// good
const errorMessage = 'This is a super long error that was thrown because ' +
'of Batman. When you stop to think about how Batman had anything to do ' +
'with this, you would get nowhere fast.';
~~~
* [6.4](https://github.com/yuche/javascript#6.4) 程序化生成字符串时,使用模板字符串代替字符串连接。
> 为什么?模板字符串更为简洁,更具可读性。
~~~
// bad
function sayHi(name) {
return 'How are you, ' + name + '?';
}
// bad
function sayHi(name) {
return ['How are you, ', name, '?'].join();
}
// good
function sayHi(name) {
return `How are you, ${name}?`;
}
~~~
- 关于
- 1. 类型
- 2. 引用
- 3. 对象
- 4. 数组
- 5. 解构
- 6. 字符串
- 7. 函数
- 8. 箭头函数
- 9. 构造函数
- 10. 模块
- 11. Iterators & Generators
- 12. 属性
- 13. 变量
- 14. 提升
- 15. 比较运算符 & 等号
- 16. 代码块
- 17. 注释
- 18. 空白
- 19. 逗号
- 20. 分号
- 21. 类型转换
- 22. 命名规则
- 23. 存取器
- 24. 事件
- 25. jQuery
- 26. ECMAScript 5 兼容性
- 27. ECMAScript 6 编码规范
- 28. 测试
- 29. 性能
- 30. 资源
- 31. 使用人群
- 32. 翻译
- 33. JavaScript 编码规范说明
- 34. 一起来讨论Javascript
- 35. Contributors
- 36. License