// 내 코드
<ul id="myMsg" class="message"></ul>
<input id="txt" type="text" placeholder="message">
<button id="btn">send</button>
// 수정한 코드
<ul id="myMessage" class="message"></ul>
<input id="text" type="text" placeholder="message">
<button id="button">send</button>
// 내 코드
if(content.includes('http://')){
index = content.indexOf('http://');
} else if (content.includes('https://')){
index = content.indexOf('https://');
}
// 수정한 코드
if (content.includes('http://')){
index = content.indexOf('http://');
} else if (content.includes('https://')){
index = content.indexOf('https://');
}
참고 : Airbnb JavaScript Style Guide
// 내 코드
if (content.includes('http://')){
index = content.indexOf('http://');
} else if (content.includes('https://')){
index = content.indexOf('https://');
}
// 수정한 코드
const httpText = 'http://';
const httpsText = 'https://';
if (content.includes(httpText)){
index = content.indexOf(httpText);
} else if (content.includes(httpsText)){
index = content.indexOf(httpsText);
}
const a = 5;
const b = 10;
console.log(`Fifteen is ${a + b} and not ${2 * a + b}`);
const aURL = `<a href ='${URL}'>${URL}</a>`;
const classes = `header ${isLargeScreen() ? '' :
(item.isCollapsed ? 'icon-expander' : 'icon-collapser')}`;
매개변수로 사용한 변수를 재할당하는 것을 지양할 것
새로운 변수에 값을 할당하여 사용하는 것을 권장함
// 내 코드
function convertToLink(content) {
...
if (index!== -1) {
const URL = content.substring(index);
const aURL = `<a href ='${URL}'>${URL}</a>`;
content = content.replace(URL, aURL);
return content;
}
}
// 수정한 코드
function convertToLink(content) {
...
if (index!== -1) {
const URL = content.substring(index);
const aURL = `<a href ='${URL}'>${URL}</a>`;
replacedContent = content.replace(URL, aURL);
return replacedContent;
}
}
// 내 코드
function prettifyISOString(iso) {
const time = new Date(iso).toLocaleTimeString('en',
{ timeStyle: 'short', hour12: false, timeZone: 'UTC'});
return time;
}
// 수정한 코드
function prettifyISOString(iso) {
const timeOptions = { timeStyle: 'short', hour12: false, timeZone: 'UTC'};
return new Date(iso).toLocaleTimeString('en', timeOptions);
}
textContent
innerText
innerHTML