string.slice
- https://developer.cdn.mozilla.net/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/String/slice
INDENTION
- use 2 space bar, not tab
Naming
- Variable
- Descriptive word
- for finance, use its term
- better to describe domain(개발 분야)'s main point
- let interestRate = 0.2
- should reflect its meaning into varible name
- Collletion
- make plural
- let animals = ['cat', 'dog', 'fish']
- Boolean,
- always make name with 'IS' and 'ARE'
- isDog = true;
- return right away if code evaluates by Boolean
- return charSet.size > text.length;
- Function
- better to start with verb that can describe function well
- let countWaterBlocksBetweenTowers ()
- Class
- start with capital
- class Animal(){}
- function Animal(){}
- Constant
- all 'CAPITAL'
- const MAX_ITEMS_IN_QUEUE = 100
Punctuation
- do not omit Curly Bracket { }
- for(key in object){
alert(key);
}
- for(key in object){
- Single Quote ' '
- can be double quote as well but do not mix
- ` Backtick
- to have it next line
- do not use '\n'
- let multilineTest = `this is line one
this is line two
this is line three`;
- Semicolone
- at the end of code
- alert('hi');
- no need for if, for, while statement
- if (condition) {
response();
}
- if (condition) {
- function expression
- let greet = function(){
alert('hi');
};
- let greet = function(){
- at the end of code
Operator & Keyword
- Loose Equality
- ==
- !=
- Strict Equality
- ===
- !==
- if (0 === '') {
alert('looks like they\'re equal');
- Ternary Operator(?)
- for simple and readable
- if (actual !== expected) {
console.log('FAILED ' + testName + ': Expected ' + expected + ', but got ' + actual);
} else {
console.log('passed');
}
- not operator(!)
- put it in front of variable
- when it is clear such as when you make code with ||
- if(!isEqual){}
Make it short
- make code clear and short
- function square(n){
return n * n;
} - Put one line space between codes
- after comma, put 1 space
- between operator, put 1 space
camelCase vs. snake_case
- do not use snake case unless constant name, always CAMELCASE in JavaScript
reference: https://google.github.io/styleguide/jsguide.html
https://github.com/airbnb/javascript
https://ko.javascript.info/coding-style
nuli.navercorp.com/data/convention/NHN_Coding_Conventions_for_Markup_Languages.pdf