Disclaimer: Of course there are always many ways to solve a problem, so the answers listed make no claim of authority, or even of "best approach." You are welcome to email sstchur(at)yahoo(dot)com if you'd like to see an alternate answer listed.

  1. What is the result of the following?

    function foo() { alert(x); var x = 10; } foo();
    1. Runtime error
    2. Will alert undefined
    3. WIll alert 10
  2. What is the result of the following?

    function foo() { x = 10; alert(x); } foo(); alert(x);
    1. Runtime error
    2. Will alert 10 once
    3. Will alert 10, followed by a runtime error
    4. Will alert 10 twice
  3. What is the result of the following?

    function foo() { alert(y); y = 10; } foo();
    1. Runtime error
    2. Will alert undefined
    3. Will alert 10
  4. What is the result of the following?

    function bar() { foo(); var foo = function() { alert(99); }; } bar();
    1. Runtime error
    2. Will alert 99
    3. Neither of the above
  5. What is the result of the following?

    function bar() { foo() function foo() { alert(99); } } bar();
    1. Runtime error
    2. Will alert 99
    3. None of the above
  6. What is the result of the following?

    function foo() { for (var i = 0; i < 5; i++) { alert(i); } alert(i); } foo();
    1. Runtime error
    2. Will alert: 0, 1, 2, 3, 4, undefined
    3. Will alert: 0, 1, 2, 3, 4, {runtime error}
    4. Will alert: 0, 1, 2, 3, 4, 5
  7. True or False?

    function Foo() { var bestBand = 'Jimmy Eat World'; this.tellMe = function() { alert(bestBand); }; } var f1 = new Foo(); var f2 = new Foo(); alert(f1.tellMe === f2.tellMe); // true or false?
    1. True
    2. False
  8. True or False?

    function Foo() { this.bestBand = 'Jimmy Eat World'; } Foo.prototype.tellMe = function() { alert(this.bestBand); }; var f1 = new Foo(); var f2 = new Foo(); alert(f1.tellMe === f2.tellMe); // true or false?
    1. True
    2. False
  9. What is the result of the following?

    var X = { x: 10, y: 20, foo: X.x * 9 };
    1. Runtime error
    2. Creates an object like, { x: 10, y: 20, foo: 90 }
    3. None of the above
  10. What is the result of the following?

    var X = { x: 10, y: 20, foo: this.x * 9 }; alert(X.foo); // just for demonstration purposes, not part of the question
    1. Runtime error
    2. Creates an object like, { x: 10, y: 20, foo: 90 }
    3. Creates an object like, { x: 10, y: 20, foo: undefined }
    4. Creates an object like, { x: 10, y: 20, foo: NaN }
    5. None of the above
  11. What is the result of the following?

    var i = 5; while (i--) { setTimeout(function() { alert(i); }, 100); }
    1. Will alert: 5, 4, 3, 2, 1
    2. Will alert: 4, 3, 2, 1, 0
    3. Will alert: 5, 4, 3, 2, 1, 0
    4. Will alert: -1, -1, -1, -1, -1
  12. Rewrite the code in Question 11 to so that it work as "expected" (that is, it alerts 5, 4, 3, 2, 1)

    1. Using the code in Question 12 as a starting point, modify the code to alert: 5, 4, 3, 2 and then 1, where each alert happens roughly 2 seconds apart.

      1. What is the value of y in the following code snippet?

        var x = 10; var y = 'steve_' + (x == 10) ? 'C' : 'D'; alert(y); // For demonstrations purposes, not part of the question
        1. 'steve_C'
        2. 'steve_D'
        3. 'C'
        4. 'D'
        5. None of the above
      2. Rewrite the code in Question 14 to produce the "expected" result (that is, 'Steve_C')

        1. Write a function, setTimeoutX, which takes 3 arguments (fnRef, ms, a). fnRef is a reference to a function that should be executed after ms milliseconds have elapsed, and the variable, a, should be passed into fnRef, when that function executes.

          1. BONUS! Write a function, setTimeoutX, which takes N arguments, the first two of which are fnRef and ms, followed by any number of additional arguments which should be passed into the fnRef function when it executes after a delay of ms milliseconds.