• 字符串统一使用单引号的形式 '',eslint: quotes

      // bad
      const department = "JDC"
      
      // good
      const department = 'JDC'
    • 程序化生成字符串时,请使用模板字符串,eslint: prefer-template template-curly-spacing

      const test = 'test'
      
      // bad
      const str = ['a', 'b', test].join()
      
      // bad
      const str = 'a' + 'b' + test
      
      // good
      const str = `ab${test}`
    • 不要对字符串使用eval(),会导致太多漏洞, eslint: no-eval

    • 不要在字符串中使用不必要的转义字符, eslint: no-useless-escape

      // bad
      const foo = '\'this\' \i\s \"quoted\"'
      
      // good
      const foo = '\'this\' is "quoted"'
      const foo = `my name is '${name}'`
    文档更新时间: 2021-05-11 16:00   作者:姚连洲