본문 바로가기

코드스테이츠(Immersive)/체크포인트

Checkpoint 01, 03-JavaScript Scopes, Keyword 'this' var x = 10; function outer () { var x = 20; function inner () { x = x + 10; return x; } inner(); } outer(); var result = x; var x = 10; function outer () { x = 20; function inner () { var x = x + 20; return x; } inner(); } outer(); var result = x; x = 20이라고 할당해준 부분에서 글로벌의 x가 20으로 변경, 이후에 inner 함수에서 x값에 20더해준뒤 리턴 var x = 10; function outer () { x = 20; function inner () { x = x + 20; } inner(); }..
Checkpoints 12 - Chatterbox Server 1번 - Assume you have the following in subject.js: var x = 10 var mod = require('./lib/my-module.js') var result = mod.x ...and the following in lib/my-module.js: var x = 20 exports.x = 30 After subject.js runs, what will be the value of result? 10 20 30 2번 - Assume you have the following in subject.js: var mod = require('./lib/my-module.js') var result = mod.x ...and the following in lib/my-modu..
Checkpoints 10 - Order of Execution 1번 - After the following code runs, what will be the value of result? var x = 10; function f () { x = x + 1; return x; } function add (x, y) { return x + y; } var result = add(x, f()); 20 21 22 2번 - After the following code runs, what will be the value of result? var x = 10; function f () { x = x + 1; } var result = x; f(); 10 11 12 3번 - After the following code runs, what will be the value of r..
Checkpoints 09 - Value vs. Reference 1번 - After the following code runs, what will be the value of x? var x = 2; var y = x; y = 3; 2 3 Not Sure 2번 - After the following code runs, what will be the value of x.foo? var x = { foo: 3 }; var y = x; y.foo = 2; 2 3 Not Sure 3번 - After the following code runs, what will be the value of x.foo? var x = { foo: 3 }; var y = x; y = 2; 2 3 undefined Reference Error 4번 - After the following code ..
Checkpoints 08 - JavaScript Callbacks 1번 - After running the following code, what will be the value of result? function doubleUp (f, x) { return f( f(x) ); }; function subject (value) { return value + "!"; }; var result = doubleUp(subject, "hi"); 1번 질문의 답을 선택하세요. * "hi" "hi!" "hi!!" "hi!!!!" 2번 - After running the following code, what will be the value of result? (You may look up JavaScript ternary operator if you need to.) function..
Checkpoint 7 - Function Binding 1번 - What message will eventually be alerted? After how long? var name = "Window"; var alice = { name: "Alice", sayHi: function() { alert(this.name + " says hi"); } }; var bob = { name: "Bob" }; setTimeout(function() { alice.sayHi(); }, 1000); 1번 질문의 답을 선택하세요. * Window says hi, after 1 second Window says hi, immediately Alice says hi, after 1 second Alice says hi, immediately Bob says hi, after ..
Checkpoints 04 - JS Prototypes(Object.create) // Object.create(prototypeObject, propertyObject); const myObject = Object.create(Object.prototype); const myLiteral = {}; const noProto = Object.create(null); // no properties const Car = function(color){ this.color = color; } const car1 = new Car('red'); // using constructor const car2 = Object.create(Car); // no constructor Car.prototype = { getColor(){ return this.color; } } const ToyCar = f..