본문 바로가기

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

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 result?

var x = 10;

function f () {
x = x + 1;
return x;
}

var result = [x, f(), x];

[10, 11, 11]
[11, 11, 11]
[10, 11, 10]
[10, 10, 10]

리턴이 없을경우 [10, undefined, 11]

 

4번 - After the following code runs, what will be the value of result?

var x = 10;

function f () {
x = x + 1;
return x;
}

var obj = {
func: f,
g: f(),
h: x,
};

obj.func();
var result = obj.g;

10
11
12
13

함수의 실행여부, 순서 확인

 

5번 - After the following code runs, what will be the value of result?

var x = 10;

function f () {
x = x + 1;
return x;
}

f();
setTimeout(f, 1000);
f();
var result = x;

10
11
12
13

 

6번 - After the following code runs, what will be the value of result?

var x = 10;

function f () {
x = x + 1;
return x;
}

f();
setTimeout(f(), 1000);
f();
var result = x;

10
11
12
13

실행표시가 있어서 바로 실행

 

7번 - After the following code runs, what will be the value of result?

var x = 10;

function f () {
x = x + 1;
return x;
}

var result = f;
result = result();

function f () {...}
10
11
Throws an error

 

 

8번 - After the following code runs, what will be the value of result?

var x = 10;

var obj = {
	y: x,
	z: obj.y + 1
};

var result = obj.z;

10
11
Throws an error

호이스팅