StudyFox
कीमतेंब्लॉगएक्सटेंशनमुफ़्त टूल
  • कीमतें
  • ब्लॉग
  • एक्सटेंशन
  • मुफ़्त टूल
  • शुरू करेंसाइन इन
StudyFox

अपने नोट्स, PDF और स्लाइड्स को फ़्लैशकार्ड, क्विज़, नोट्स और माइंड मैप में बदलें।

StudyFox खोलें

स्टडी टूल्स

  • होमवर्क हेल्पर
  • नोट मेकर
  • फ़्लैशकार्ड मेकर
  • क्विज़ मेकर
  • माइंड मैप मेकर

प्रोडक्ट

  • कीमतें
  • Chrome एक्सटेंशन
  • मुफ़्त एक्सटेंशन
  • स्टडी सेट देखें
  • ब्लॉग

सहायता

  • सहायता केंद्र
  • संपर्क करें
  • गोपनीयता नीति
  • सेवा की शर्तें

तुलना करें

  • Chegg का विकल्प
  • Course Hero का विकल्प
  • Coursology का विकल्प
  • Photomath का विकल्प
  • Gauthmath का विकल्प
  • PhotoSolve का विकल्प
  • CollegeTools का विकल्प
  • Transcript का विकल्प
  • SmartSolve का विकल्प
  • Homeworkify का विकल्प
  • AnswersAi का विकल्प
  • StudyX का विकल्प
  • Quizlet का विकल्प
  • Anki का विकल्प
  • Knowt का विकल्प
  • Brainscape का विकल्प
  • सभी तुलनाएँ

© 2026 StudyFox AI. सर्वाधिकार सुरक्षित।

  • X
  • Discord
  • Instagram
ExploreEngineering & TechWeb DevelopmentJavaScript Advanced Quiz: this, Prototypes, Iterators & Async Ordering

Quiz · Hard

JavaScript Advanced Quiz: this, Prototypes, Iterators & Async Ordering

Harder questions on bound this, prototype shadowing, class fields, microtask ordering, generators, iterators, key order and module behavior. Output questions were run to confirm the answers.

by Kill h.17 questionsCreated Nov 20, 2026, 08:27 PM
Web Development· JavaScriptTags#javascript#prototypes#generators#advanced

17 questions

  1. 1

    What does this code print?

    function f() { return this.x; }
    const a = { x: 1 }, b = { x: 2 };
    const g = f.bind(a);
    console.log(g.call(b), f.call(b));
    • 1 2

    • B

      2 1

    • C

      2 2

    • D

      1 1

    A bound function permanently fixes this; a later call cannot change it, so g.call(b) still uses a and returns 1. f.call(b) on the original function uses b and returns 2.

  2. 2

    What does this code print?

    class A {
      m() {}
      p = () => {};
    }
    const x = new A(), y = new A();
    console.log(x.m === y.m, x.p === y.p);
    • true false

    • B

      false true

    • C

      false false

    • D

      true true

    Methods defined in the class body live once on A.prototype, so all instances share the same function. A class field with an arrow function creates a new function per instance (handy for keeping this, but costs memory).

  3. 3

    What does this code print?

    function F() {}
    F.prototype.v = 1;
    const o = new F();
    F.prototype = { v: 2 };
    const p = new F();
    console.log(o.v, p.v);
    • 1 2

    • B

      1 1

    • C

      2 1

    • D

      2 2

    An instance's prototype is fixed at creation. o still points to the old prototype object (v = 1). Re-assigning F.prototype only affects objects created afterwards.

  4. 4

    What does this code print?

    const proto = { n: 1 };
    const o = Object.create(proto);
    o.n++;
    console.log(o.n, proto.n, Object.hasOwn(o, 'n'));
    • 2 1 true

    • B

      2 2 false

    • C

      1 1 false

    • D

      2 1 false

    o.n++ reads n through the prototype (1) but writes to o itself, creating an own property n = 2 that shadows the prototype's. The prototype object is unchanged.

  5. 5

    What does this code print?

    async function a() {
      console.log('a1');
      await b();
      console.log('a2');
    }
    async function b() { console.log('b'); }
    console.log('s');
    a();
    Promise.resolve().then(() => console.log('p'));
    console.log('e');
    • A

      s e a1 b a2 p

    • B

      s a1 b a2 e p

    • C

      s a1 e b a2 p

    • s a1 b e a2 p

    Everything before the first await runs synchronously (s, a1, b), then the script ends with e. Microtasks run in the order queued: the continuation of a (a2) was queued before the .then (p).

  6. 6

    What does this code print?

    Promise.resolve().then(() => console.log(1)).then(() => console.log(2)).then(() => console.log(3));
    Promise.resolve().then(() => Promise.resolve()).then(() => console.log('A'));
    • A

      A 1 2 3

    • B

      1 2 A 3

    • 1 2 3 A

    • D

      1 A 2 3

    Returning a promise from a .then handler makes the outer promise wait for it, which costs extra microtask ticks. So A falls behind the plain chain, even though both started together.

  7. 7

    What does this code print?

    function f() {
      try {
        return 'try';
      } finally {
        console.log('finally');
      }
    }
    console.log(f());
    • A

      try

    • B

      try finally

    • C

      finally

    • finally try

    A finally block always runs, even after a return in try. It runs before the function actually returns, so 'finally' is logged first and then the returned value is printed.

  8. 8

    What does this code print?

    function* g() {
      const x = yield 1;
      console.log(x);
      yield 2;
    }
    const it = g();
    console.log(it.next().value, it.next('hi').value);
    • A

      1 hi 2

    • B

      1 2

    • hi 1 2

    • D

      hi 2 1

    The argument of the second next('hi') becomes the result of the paused yield 1, so x is 'hi' and is logged while evaluating the arguments of the outer console.log, which then prints 1 and 2.

  9. 9

    What does this code print?

    const r = {
      from: 1,
      to: 3,
      [Symbol.iterator]() {
        let c = this.from, t = this.to;
        return { next: () => (c <= t ? { value: c++, done: false } : { value: undefined, done: true }) };
      }
    };
    console.log([...r]);
    • [1, 2, 3]

    • B

      [1, 3]

    • C

      TypeError: r is not iterable

    • D

      []

    Spread and for...of call obj[Symbol.iterator]() and then next() until done is true. Any object that implements the protocol is iterable.

  10. 10

    What does this code print?

    console.log(Array(3).map((_, i) => i), Array.from({ length: 3 }, (_, i) => i));
    • A

      [0, 1, 2] [0, 1, 2]

    • B

      [undefined, undefined, undefined] [0, 1, 2]

    • [ <3 empty items> ] [0, 1, 2]

    • D

      [] [0, 1, 2]

    Array(3) creates three holes, and map skips holes, so nothing is mapped. Array.from({ length: 3 }, fn) visits every index.

  11. 11

    What does this code print?

    console.log([] == ![], null >= 0, null == 0);
    • A

      true false false

    • true true false

    • C

      false true true

    • D

      false false false

    ![] is false; [] == false converts both to 0 ('' to 0), so it is true. null >= 0 converts null to 0 for the relational comparison (true), but null == 0 is false because == only equates null with undefined.

  12. 12

    What does this code print?

    const o = {};
    console.log(o.a?.b.c, o.f?.());
    • undefined undefined

    • B

      null undefined

    • C

      undefined null

    • D

      TypeError

    Optional chaining short-circuits the whole rest of the chain: o.a?.b.c stops at a (undefined), so .c is never read. o.f?.() does not call f because it is undefined.

  13. 13

    What does this code print?

    console.log(Object.keys({ b: 1, 2: 1, a: 1, 1: 1 }));
    • A

      ['b', '2', 'a', '1']

    • B

      ['1', '2', 'a', 'b']

    • [ '1', '2', 'b', 'a' ]

    • D

      ['b', 'a', '1', '2']

    Own property order: integer-like keys first in ascending numeric order, then string keys in insertion order (then symbols). So 1, 2, then b, a.

  14. 14

    Two modules both import { counter } from './state.js'. How many times does state.js execute, and are the imports shared?

    • A

      Every time counter is accessed

    • B

      Twice, then it is cached

    • Once; both get the same live bindings of the same module instance

    • D

      Once per importing module; each gets its own copy

    ES modules are singletons per URL: evaluated once and cached. Imports are live bindings to the exported variables, so changes made inside state.js are visible to all importers (importers cannot assign to them directly).

  15. 15

    try { setTimeout(() => { throw new Error('x'); }, 0); } catch (e) { console.log('caught'); }: what happens?

    • A

      The timer never runs

    • B

      The error is silently ignored

    • The error is not caught; it surfaces later as an uncaught exception

    • D

      'caught' is logged

    The callback runs later as its own macrotask, after the try/catch has finished, so that call stack no longer exists. Handle errors inside the callback (or use promises with .catch).

  16. 16

    A class declares #secret = 1. What happens with obj.#secret outside the class body?

    • A

      A TypeError at runtime only

    • A SyntaxError at parse time

    • C

      undefined

    • D

      It works, but logs a warning

    Private names are checked statically: referring to #secret outside the class is an early SyntaxError, not just undefined. Reading a private field on an object that lacks it inside the class throws a TypeError.

  17. 17

    const f = obj.method; f(); fails because this is lost. Which fix does not work?

    • obj.method.call() with no arguments

    • B

      obj.method() called directly

    • C

      const f = () => obj.method()

    • D

      const f = obj.method.bind(obj)

    call() with no thisArg calls the function with this undefined (strict) or the global object, so it does not restore obj. bind(obj), an arrow wrapper and a direct member call all keep obj as this.