본문 바로가기

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

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
2
0
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-module.js:

var x = 10
exports.x = 20
module.exports.x = 30

After subject.js runs, what will be the value of result?

10
20
30

 

3번 - Assume you have the following in subject.js:

var mod1 = require('./lib/my-module.js');
var mod2 = require('./lib/my-module.js');

var result = (mod1 === mod2);

...and the following in lib/my-module.js:

exports.obj = { name: "Alice" };

After subject.js runs, what will be the value of result?

true

false

 

4번 - Assume you have the following in subject.js:

var mod1 = require('./lib/my-module.js');
var mod2 = require('./lib/my-module.js');

mod1.increment();
var result = mod2.increment();

...and the following in lib/my-module.js:

var counter = 0;
exports.increment = function () {
counter += 1;
return counter;
};

After subject.js runs, what will be the value of result?

0
1
2

동일한 위치에서 카운터를 참조(모듈이 클로저 함수로 구현)

 

5번 - Assume you have the following in subject.js:

var mod1 = require('./lib/my-module.js');
var mod2 = require('./lib/my-module.js');

...and the following in lib/my-module.js:

console.log("Loading module!")

After subject.js runs, how many logs in the console will you see?

0
1
2

이미 로드가 되있기 때문에 

 

6번 - After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(function() {
console.log("B");
}, 1000);

setTimeout(function() {
console.log("C");
}, 500)

console.log("D");

A B C D

A C B D

A D B C

A D C B

 

7번 - After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(function() {
console.log("B");
}, 0);

console.log("C");

A B C

A C B

Event Loop

 

8번 - Assume superLongComputation() is synchronous and takes 5 seconds to run. After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(function() {
console.log("B");
}, 1000);

superLongComputation();

console.log("C");

A B C

A C B

 

9번 - Assume superLongComputation() is synchronous and 5 seconds to run. After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(function() {
console.log("B");
}, 1000);

superLongComputation();

setTimeout(function() {
console.log("C");
}, 500);

console.log("D");

A B C D

A C B D

A D B C

A D C B

A B D C

 

10번 - After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(function() {
console.log("B");
}, 500);

setTimeout(console.log("C"), 1000);

ABC

ACB

 

11번 - After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(go, 100);

setTimeout(function() {
console.log("B");
}, 50);

function go () {
console.log("X")
}

AXB

ABX

 

12번 - After all setTimeout callbacks have run, what order of letters will be shown in the console?

console.log("A");

setTimeout(go(), 100);

setTimeout(function() {
console.log("B");
}, 50);

function go () {
console.log("X")
}

AXB

ABX