padStart() 메서드는 현재 문자열의 시작을 다른 문자열로 채워, 주어진 길이를 만족하는 새로운 문자열을 반환합니다. 채워넣기는 대상 문자열의 시작(좌측)부터 적용됩니다.
var num = 123;
console.log(String(num).padStart(5, "0")); // '00123'
var text = "abc";
console.log(text.padStart(5, " ")); // ' abc'
padEnd() 메서드는 현재 문자열에 다른 문자열을 채워, 주어진 길이를 만족하는 새로운 문자열을 반환합니다. 채워넣기는 대상 문자열의 끝(우측)부터 적용됩니다.
var num = 123;
console.log(String(num).padEnd(5, "0")); // '12300'
var text = "abc";
console.log(text.padEnd(5, " ")); // 'abc '
startsWith() 메서드는 어떤 문자열이 특정 문자로 시작하는지 확인하여 결과를 true 혹은 false로 반환합니다.
const str1 = 'Saturday night plans';
console.log(str1.startsWith('Sat'));
// Expected output: true
console.log(str1.startsWith('Sat', 3));
// Expected output: false
Number.isInteger() 메서드는 주어진 값이 정수인지 판별합니다.
function fits(x, y) {
if (Number.isInteger(y / x)) {
return 'Fits!';
}
return 'Does NOT fit!';
}
console.log(fits(5, 10));
// Expected output: "Fits!"
console.log(fits(5, 11));
// Expected output: "Does NOT fit!"
eval()은 문자로 표현된 JavaScript 코드를 실행하는 함수입니다.
console.log(eval('2 + 2'));
// Expected output: 4
console.log(eval(new String('2 + 2')));
// Expected output: 2 + 2
console.log(eval('2 + 2') === eval('4'));
// Expected output: true
console.log(eval('2 + 2') === eval(new String('2 + 2')));
// Expected output: false
str.repeat(count);
"abc".repeat(-1); // RangeError
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'