문자열(Strings)
문자열에는 싱크쿼트
''
를 사용해 주십시오.// bad const name = "Capt. Janeway"; // good const name = 'Capt. Janeway';
Strings longer than 100 characters should be written across multiple lines using string concatenation.
100문자 이상의 문자열은 문자열연결을 사용해서 복수행에 걸쳐 기술할 필요가 있습니다.
Note: If overused, long strings with concatenation could impact performance. jsPerf & Discussion.
주의: 문자연결을 과용하면 성능에 영향을 미칠 수 있습니다. jsPerf & Discussion.
// 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 When programmatically building up strings, use template strings instead of concatenation.
6.4 프로그램에서 문자열을 생성하는 경우는 문자열 연결이 아닌 template strings를 이용해 주십시오.
Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.
왜? Template strings 는 문자열 보간기능과 적절한 줄바꿈 기능을 갖는 간결한 구문으로 가독성이 좋기 때문입니다.
// 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}?`; }
Never use
eval()
on a string, it opens too many vulnerabilities.절대로
eval()
을 이용하지 마십시오. 이것은 많은 취약점을 만들기 때문입니다.
'개발 > Javascript' 카테고리의 다른 글
Classes & Constructors (0) | 2018.03.11 |
---|---|
함수(Functions) (0) | 2018.03.11 |
구조화대입(Destructuring) (0) | 2018.03.11 |
배열(Arrays) (0) | 2018.03.11 |
오브젝트(Objects) (0) | 2018.03.11 |