ノートをまちがえる


解題スペース
#01 what is the value of `x` after running the code below?
NOTE! we are asking for x not the reuslt (문제는 x의 값을 묻고 있습니다)

var x = 30;

function get(x) {
  return x;
}
function set(value) {
  x = value;
}

set(10);
var result = get(20);

20
→xの値を尋ねてresultで回答する.エラー読み出し問題xの値は10
#02 What is the value of `result` after running the code below?
var x = 10;

function outer() {
  var x = 20;
  function inner() {
    x = x + 10;
    return x;
  }
  inner();
}

outer();
var result = x;
20
#09 What is the `result` after running the code below
var obj1 = { x: 10 };
var obj2 = Object.create(obj1);

var obj3 = Object.create(obj2);

obj2.x = 20;

var result = obj3.x + 10;
30
→obj 2のフレームを借りて、同じアドレスを見ている.obj 3に新しいx値が割り当てられていないため、obj 2のx値が変更されるとobj 3の値も変更される.obj 3にすでに値が割り当てられている場合、obj 2のx変化も影響を受けない.
また、obj 3の値が変化しても、obj 2は影響を受けません.
#10 What is the Big O time complexity for searching for a value in an unsorted array ?
O(n) Linear
#11 What is the Big O time complexity for retrieving the value at a specific index in a linked list ? *
O(n) Linear
#12 What is the worst case Big O time complexity of inserting a value into a binary search tree ? *
O(n) Linear
リファレンス
# 14 After running the code below what message will be eventually be alerted and after how long?
var name = 'Window';
var alice = {
  name: 'Alice',
  sayHi: function() {
    alert(this.name + ' says hi');
  }
};

var bob = { name: 'Bob' };

setTimeout(alice.sayHi.bind(alice), 1000);
Alice says hi, after 1 sec
→bindで値を取得し、1秒後に反映する
# 15 After running the code below what message will be eventually be alerted and after how long?
var name = 'Window';
var alice = {
  name: 'Alice',
  sayHi: function() {
    alert(this.name + ' says hi');
  }
};
var bob = { name: 'Bob' };
setTimeout(alice.sayHi.call(bob), 1000);
Bob says hi, immediately
→あなたが持っている価格ではないので、呼んだら実行
# 16 After running the code below what message will be eventually be alerted and after how long?
var name = 'Window';
var alice = {
  name: 'Alice',
  sayHi: function() {
    alert(this.name + ' says hi');
  }
};
var bob = { name: 'Bob' };

alice.sayHi.bind(bob);

setTimeout(alice.sayHi(), 1000);
Alice says hi, immediately
→bindは反映せず、ボトムで直ちに実行
function foo() {
  var data = 10;

  bar(function(players) {
    data = players;
  });

  return data;
}

function bar(callback) {
  setTimeout(callback, 0);
}

let result = foo();
10
→callback関数にplayesrsに渡される値がないので、10を選択
#19 After the following code runs, what will be the value of player.score?
var player = { score: 3 };
function doStuff(obj) {
  obj.score = 2;
  obj = undefined;
}
doStuff(player);
答えは2
→戻り値がないため、関数実行はundefinedになりますが、scoreは2に反映されます.同じ住所を見ているようです.関数内部にのみ適したobjが定義されていないため、プレーヤーは影響を受けません.