///////
Search

+ 예전 스터디 퀴즈

문제1. 소스코드 타입 4가지를 말하시오.
문제2. 렉시컬 환경은 (a)와 (b)와 (c)에 대한 참조를 기록하는 자료구조이다.
문제3. 클로저는 함수와 그 함수가 선언된 (a)의 조합이다.
문제4.
function makeCounter() { let count = 0; return function() { return count++; }; } let counter = makeCounter(); let counter1 = makeCounter(); console.log( counter() ); //? console.log( counter() ); // ? console.log( counter1() ); // ? console.log( counter1() ); // ?
JavaScript
복사
4.1 추가문제
function addSomething(x){ return function add(y){ return x + y; }; } const addFive = addSomething(5); const addTen = addSomething(10); const result1 = addTen(10) const result2 = addFive(5) const result3 = addTen(20) console.log(result1) //? console.log(result2) //? console.log(result3)//?
JavaScript
복사
문제 5. sum(a)(b) = a+b와 같은 연산을 해주는 함수 sum을 만들어보세요.
문제 6. (나중에 심심할때?)
function add (num) { // your solution } // 아래에 주어진 케이스에 대응할 수 있도록 `add` 함수를 작성해주세요. // 주어진 두 가지 케이스 외에는 대응하지 않아도 됩니다. const six = add(1)(2)(3); const ten = add(2)(3)(5); console.log(six); // 6 console.log(ten); // 10
JavaScript
복사
문제7. 클래스에서 생성자는 여러개 가질 수 있다. (o/x)
문제8.
// 운송수단 class Vehicle { constructor(acceleration = 1) { this.speed = 0 this.acceleration = acceleration } accelerate() { this.speed += this.acceleration } decelerate() { if (this.speed <= 0) { console.log('정지!') return } this.speed -= this.acceleration } } // 자전거 class Bicycle extends Vehicle { constructor(price = 100, acceleration) { super(acceleration) this.price = price this.wheel = 2 } } const bicycle = new Bicycle(300) bicycle.accelerate() console.log(bicycle.speed) // console.log(bicycle.wheel) // console.log(bicycle.price) // console.log(bicycle instanceof Bicycle) // console.log(bicycle instanceof Vehicle) // console.log(bicycle.constructor === Bicycle) // console.log(bicycle.constructor === Vehicle) // // 자동차 class Car extends Bicycle { constructor(license, price, acceleration) { super(price, acceleration) this.license = license this.wheel = 4 } // 오버라이딩(Overriding) accelerate() { if (!this.license) { console.error('무면허!') return } this.speed += this.acceleration console.log('가속!', this.speed) } } const carA = new Car(true, 7000, 10) const carB = new Car(false, 4000, 6) carA.accelerate() // carB.accelerate() // console.log(carA instanceof Car) // console.log(carA instanceof Bicycle) // console.log(carA instanceof Vehicle) // console.log(carA.constructor === Car) // console.log(carA.constructor === Bicycle) // console.log(carA.constructor === Vehicle) //
JavaScript
복사