Ex) DOM, XMLHttpRequest
str.length
나 str.toUpperCase()
등을 보면 String은 원시값임에도 마치 객체로 동작한다.String, Number, Boolean
+ Symbol
JS엔진이 객체 중 가장 먼저 생성하는 특수한 객체
globalThis: 환경에 따라 제각각인 전역 객체의 이름을 통일한 것 (브라우저: window / Node: global)
특징
var vs let & const
eval: JS코드를 인자로 받아 평가하여 값을 생성하거나 동작시키는 함수
금지이유
isFinite
false
isNan: 숫자가 아닌지 확인 (숫자가 아니면 숫자로 변환 후 검사)
parseFloat: 실수로 해석
parseInt(str,X): X진수인 str를 10진수로 변환
Ex) Num.toString(X);
encodeURI & decodeURI: URI 인코딩 & 디코딩
encodeURIComponent & decodeURIComponent: URI 구성 요소를 인코딩 & 디코딩
NaN | undefined | null | |
---|---|---|---|
의미 | 숫자가 아님. | 정의가 안됨. | 아무것도 나타내지 않음. |
Boolean | false | false | false |
Number | NaN | NaN | 0 |
String | NaN | undefined | null |
undefined는 왜 Number에서 NaN일까?
NaN
이라고 처리한 것 같다.0
이라고 처리한 것 같다.Function.prototype.(apply, call, bind)
를 사용한다.메서드는 프로퍼티에 바인딩된 함수이다.
메서드 내부의 this는 메서드를 정의한 객체가 아닌 메서드를 호출한 객체에 바인딩된다.
const cir1 = {
rad: 3,
getDiameter() {
return this.rad * 2;
},
};
const cir2 = {
rad: 5,
};
cir2.getDiameter = cir1.getDiameter;
console.log(cir1.getDiameter()); // 6
console.log(cir2.getDiameter()); // 10
cir2.getDiameter()
는 정의한 cir1.rad이 아닌 호출한 cir2.rad를 이용한 값을 리턴한다.Function.prototype.(apply, call, bind)
이용Function.prototype.apply(thisArg[,argsArray])
Function.prototype.call(thisArg[,arg1[, ...]])
thisArg
을 this로 전달한다.
두 번째 인자들부터 함수의 인자로 전달한다.
함수를 실행한다. (Function.prototype
) - apply는 배열로, call은 쉼표로 구분된 인자를 전달하는 것만이 다르다.
function getArgs() {
console.log(arguments);
const slice = Array.prototype.slice;
console.log(slice);
const arr = slice.call(arguments);
console.log(arr, this);
return arr;
}
console.log(getArgs(1, 2, 3));
(1,2,3)
이 인자로 들어와 이들을 이용해 배열을 만들었다.Function.prototype.bind(thisArg[,arg1[, ...]])