
코드스테이즈 41기 교육 내용을 정리하고 있습니다.
틀린 부분이 있으면 댓글로 알려주시면 감사하겠습니다.
코드스테이츠 'Javascript Koans' 시간에 배운내용을 정리했습니다
Scope
let age = 25;
let name = 'leewang';
let height = 181;
function outerFn() {
let age = 23;
name = 'kim';
let height = 153;
function innerFn() {
age = 29;
let name = 'man';
return height;
}
innerFn();
console.log(age); //29
console.log(name); //'kim'
return innerFn;
}
const innerFn = outerFn();
console.log(age); // 25
console.log(name); // 'kim'
console.log(innerFn()); // 153

Array.slice()
const arr = ['apple', 'banana', 'cat', 'dog'];
arr.slice(1) //['banana', 'cat', 'dog']
arr.slice(0,1) //['apple']
arr.slice(0,2) //['apple', 'banana']
arr.slice(2,2) //[]
arr.slice(2,20) //['cat', 'dog']
arr.slice(3,0) //[]
arr.slice(3,100) //['dog']
arr.slice(5,1) //[]
arr.slice(0) //['apple', 'banana', 'cat', 'dog']
arr.slice() //['apple', 'banana', 'cat', 'dog']
Object property (in)
const cart ={ fruit : 'Apple', snack: 'cookie'}
console.log('snack' in cart) //true
console.log('Apple' in cart) //false
console.log('computer' in cart) //false
this
const result = 1000
const cal = {
number: 500,
minus: function (numPrams) {
return numPrams - this.number;
},
changeNum: function (numPrams) {
this.number = numPrams;
},
};
console.log(result) //1000
console.log(cal.minus(result)) //500
cal.number = 40;
console.log(cal.minus(result)) //960
cal.changeNum(100);
console.log(cal.minus(result)) //900
this.number
this를 사용하면서 함수스코프에 들어올수 없었던 외부변수 number를 사용할 수 있게 하였다.
'프론트엔드 > Codestates' 카테고리의 다른 글
| [JavaScript/Web] Dom다루기 (0) | 2022.09.13 |
|---|---|
| [Javascript/Web] DOM의 기초 (0) | 2022.09.13 |
| [JavaScript] ES6 주요 문법 (spread/rest, 구조 분해) (0) | 2022.09.07 |
| [JavaScript] 클로저 (0) | 2022.09.07 |
| [JavaScript] 스코프 (0) | 2022.09.06 |