JS에서 문자열 슬라이싱하는 데 사용된다.
const str = "hello world";
const substr1 = str.substring(0, 5); // "hello"
const substr2 = str.substring(6); // "world"
인자 두개를 넣으면, a번째 인덱스부터 b-1번째 인덱스까지 슬라이싱한다.
인자 한개를 넣으면, a번째 인덱스부터 문자열 끝까지 슬라이싱한다.
숫자가 정수형인지를 boolean으로 반환한다.
const num1 = 5;
const num2 = 5.0;
const num3 = "5";
const num4 = 5.5;
console.log(Number.isInteger(num1)); // true
console.log(Number.isInteger(num2)); // true
console.log(Number.isInteger(num3)); // false
console.log(Number.isInteger(num4)); // false
5.0도 true라는 사실만 기억하자.
주어진 값이 숫자인지 아닌지를 boolean으로 반환한다.
const num1 = NaN;
const num2 = 5;
const num3 = "hello";
console.log(isNaN(num1)); // true
console.log(isNaN(num2)); // false
console.log(isNaN(num3)); // true