코드 컨벤션
Extension Used
•
Formatter : Prettier
.prettierrc
{
"$schema": "<https://json.schemastore.org/prettierrc>",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
YAML
복사
•
Linter : ESLint
네이밍 가이드라인
타입 | 네이밍 | Example |
컴포넌트 | PascalCase | CapWords |
패키지 | PascalCase | CapWords |
클래스 | PascalCase | CapWords |
예외(Exception) | PascalCase | CapWords |
함수 | camelCase | camelCase() |
상수 | UPPER_CASE | CAPS_WITH_UNDER |
변수 | camelCase | camelCase |
메서드 | camelCase | camelCase() |
함수/메서드 매개변수 | camelCase | camelCase |
변수 선언 : let, const이용, 1 by 1
•
var 보단 let, const를 이용
•
한번의 선언에서 하나의 변수만을 선언
◦
선언도 제대로 안되고 오류가 자주 발생
const num1 = 0
const num1 = 0
const num1 = 0
(O)
==================
const num1, num2, num3 = 0
const num1 = num2 = num3 = 0
const num1 = const num2 = const num3 = 0
(X)
JavaScript
복사
조건문 : ==과 !=대신에 ===과 !==를 사용
•
명시적 타입 검증: ===과 !==는 타입 변환을 수행하지 않기 때문에, 코드의 의도를 보다 명확하게 표현할 수 있다. 타입 변환에 의한 예기치 않은 동작을 방지할 수 있다.
•
버그 예방: 암시적 타입 변환으로 인해 발생할 수 있는 버그를 줄일 수 있다.
예를 들어, 0 == false는 true를 반환하지만, 0 === false는 false를 반환하여 버그를 예방할 수 있다.
•
코드의 가독성: ===과 !==를 사용하면 비교할 때 의도하지 않은 타입 변환을 방지할 수 있어, 코드가 더 직관적이고 이해하기 쉬워진다.