[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Execution_model [Back]  [Original]

- JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

JavaScript , , , C Java .

In this article

. JavaScript .

, , [, , ]

'' .

js
function foo(b) {
  const a = 10;
  return a + b + 11;
}

function bar(x) {
  const y = 3;
  return foo(x * y);
}

const baz = bar(7); // 42 baz 

.

  1. bar , bar .
  2. bar foo , foo .
  3. foo , (bar ).
  4. bar , .

, . .

. ( ) .

JavaScript , . .

, . , . .

. , .

, .

js
while (queue.waitForMessage()) {
  queue.processNextMessage();
}

queue.waitForMessage() .

"Run-to-completion"

.

. , , . , C , .

, . " " . , .

, . , . , . .

setTimeout . , ( , 0). () . setTimeout . , setTimeout . , '' .

setTimeout .

js
const seconds = new Date().getTime() / 1000;

setTimeout(function () {
  // "2" ,  500       
  console.log(`${new Date().getTime() / 1000 - seconds}  .`);
}, 500);

while (true) {
  if (new Date().getTime() / 1000 - seconds >= 2) {
    console.log(", 2 .");
    break;
  }
}

0

0 0 . setTimeout 0 .

. ' ' . '' , .

setTimeout , .

js
(function () {
  console.log("");

  setTimeout(function cb() {
    console.log(" 1:  ");
  }); // has a default time value of 0

  console.log(" ");

  setTimeout(function cb1() {
    console.log(" 2:  ");
  }, 0);

  console.log("");
})();
js
(() => {
  console.log("");

  setTimeout(() => {
    console.log(" 1:  ");
  }); //    0 .

  console.log("this is just a message");

  setTimeout(() => {
    console.log(" 2:  ");
  }, 0);

  console.log("this is the end");
})();

// ""
// " "
// ""
// " 1:  "
// " 2:  "

iframe , , . postMessage . message , postMessage .

JavaScript . , , IndexedDB XHR , .

alert XHR . ( ).


Web Proxy Viewer  |  New URL  |  Original Page