MAD Study Hub

Home / Past papers / MAD2 Quiz 1 / this paper

IIT M IMPROVEMENT AN EXAM QIO3 13 July - 13 Jul 2025

MAD2 Quiz 116 questions50 marks15 MCQ · 1 MSQImprovement / afternoon / QIO3
Elapsed 00:00
Q1MCQ2 marks
In Vue 2, what happens when you update a data property?
  1. DOM is immediately updated without virtual DOM
  2. The page reloads
  3. The virtual DOM detects changes and updates efficiently
  4. A full component re-renders from scratch
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following HTML, with the correct Vue 2 CDN links included:
Html code.

```html
<div id="app">
  <h3>Shopping Cart</h3>
  <p>Items: {{itemCount}}</p>
  <p>Total Cost: ${{totalCost}}</p>
  <button @click="addItem">Add Item ($15)</button>
  <button @click="removeItem">Remove Item</button>
  <p>Status: {{status}}</p>
</div>
```

script:

```javascript
const app = new Vue({
  el: '#app',
  data() {
    return {
      itemCount: 0,
      itemPrice: 15,
      totalCost: 0
    }
  },
  computed: {
    status() {
      if (this.itemCount === 0) {
        return 'Empty Cart';
      } else if (this.itemCount < 3) {
        return 'Few Items';
      } else {
        return 'Full Cart';
      }
    }
  },
  methods: {
    addItem() {
      this.itemCount++;
      this.totalCost += this.itemPrice;
    },
    removeItem() {
      if (this.itemCount > 0) {
        this.itemCount--;
        this.totalCost -= this.itemPrice;
      }
    }
  }
})
```

If the user clicks the "Add Item" button 3 times, then clicks the "Remove Item" button 1 time, what will be displayed for Items, Total Cost, and Status?
  1. Items: 2, Total Cost: $30, Status: Few Items
  2. Items: 2, Total Cost: $45, Status: Few Items
  3. Items: 3, Total Cost: $30, Status: Full Cart
  4. Items: 2, Total Cost: $30, Status: Full Cart
  5. Items: 1, Total Cost: $15, Status: Few Items
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following code.

```javascript
const arr = [1, 2, 3];
const result = arr.map(function(item, index) {
  return this[index] * item;
}, [10, 20, 30]);
console.log(result);
```

What will be the output?
  1. [1, 2, 3]
  2. [10, 40, 90]
  3. [10, 20, 30]
  4. [NaN, NaN, NaN]
Q4MCQ2 marks
question figure
Text of the picture (copyable)
In Vue 2, which of the following will NOT trigger reactivity?
```javascript
data() {
  return {
    items: [1, 2, 3],
    obj: { a: 1 }
  }
}
```
  1. this.items.push(4)
  2. this.items[0] = 10
  3. this.items = [10, 2, 3]
  4. this.obj.a = 2
Q5MCQ3 marks
question figure
Text of the picture (copyable)
What will be the output of this code?

```javascript
function createFunctions() {
  var funcs = [];
  for (var i = 0; i < 3; i++) {
    funcs.push(function() {
      return i;
    });
  }
  return funcs;
}

const functions = createFunctions();
console.log(functions[0](), functions[1](), functions[2]());
```
  1. 0, 1, 2
  2. 1, 2, 3
  3. undefined, undefined, undefined
  4. 3, 3, 3
Q6MCQ3 marks
Which computed property implementation is INCORRECT?
  1. question figure
    text
    ```javascript
    computed: {
      fullName() {
        return this.firstName + ' ' + this.lastName;
      }
    }
    ```
  2. question figure
    text
    ```javascript
    computed: {
      fullName: {
        get() { return this.firstName + ' ' + this.lastName; },
        set(value) {
          const names = value.split(' ');
          this.firstName = names[0];
          this.lastName = names[1];
        }
      }
    }
    ```
  3. question figure
    text
    ```javascript
    computed: {
      async fullName() {
        return await this.fetchFullName();
      }
    }
    ```
  4. question figure
    text
    ```javascript
    computed: {
      fullName: function() {
        return this.firstName + ' ' + this.lastName;
      }
    }
    ```
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code:

```javascript
const products = [
  { id: 101, name: "laptop", price: 800 },
  { id: 102, name: "mouse", price: 25 },
  { id: 103, name: "keyboard", price: 60 },
  { id: 104, name: "monitor", price: 300 }
];

const priorities = { "102": 1, "104": 2, "101": 3, "103": 4 };

products
  .filter((product) => product.price > 50)
  .map((product) => {
    return { ...product, priority: priorities[product.id] }
  })
  .sort((a, b) => a.priority - b.priority)
  .forEach((product) => {
    console.log(product.name);
  });
```

What will be the output of the code?
  1. question figure
    text
    ```
    laptop
    keyboard
    monitor
    ```
  2. question figure
    text
    monitor
    laptop
    keyboard
  3. question figure
    text
    ```
    mouse
    monitor
    laptop
    keyboard
    ```
  4. question figure
    text
    ```
    laptop
    mouse
    keyboard
    monitor
    ```
  5. question figure
    text
    The code will throw an error
Q8MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code to answer the below question:

```javascript
const grandParent = {
    username: 'GrandParent',
    getName: function () {
        return this.username;
    },
    parent: {
        username: 'Parent',
        getName: function () {
            return this.username;
        },
        child: {
            username: 'Child',
            getNameArrow: () => {
                return this.username;
            },
            getNameFunc: function () {
                return this.username;
            }
        }
    }
};

console.log("A: " + grandParent.getName());
console.log("B: " + grandParent.parent.getName());
console.log("C: " + grandParent.parent.child.getNameFunc());
console.log("D: " + grandParent.parent.child.getNameArrow());
```

What will be the result of all the console.log after execution of the above code?
  1. question figure
    text
    A: GrandParent
    B: Parent
    C: Child
    D: Reference Error
  2. question figure
    text
    A: GrandParent
    B: Parent
    C: undefined
    D: Child
  3. question figure
    text
    A: GrandParent
    B: GrandParent
    C: Parent
    D: GrandParent
  4. question figure
    text
    ```
    A: GrandParent
    B: Parent
    C: Child
    D: undefined
    ```
Q9MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue.js (Vue 2) code to answer the following question:

```html
<div id="app">
  <my-counter :start="5"></my-counter>
</div>

<script>
  Vue.component('my-counter', {
    props: ['start'],
    data: function () {
      return {
        count: this.start
      };
    },
    template: `
      <div>
        <p>{{ count }}</p>
        <button @click="increment">Increment</button>
      </div>
    `,
    methods: {
      increment() {
        this.count++;
      }
    }
  });

  new Vue({
    el: '#app',
    data: { start: 10 }
  });
</script>
```

What will be displayed when the page loads, and what happens when you click the button?
  1. question figure
    text
    The counter starts at 10, and increments by 1 on each button click.
  2. question figure
    text
    The counter starts at 5, and increments by 1 on each button click.
  3. question figure
    text
    Nothing is rendered because the Vue component template is invalid when using Vue via CDN.
  4. question figure
    text
    Vue throws a warning about compiling templates in the browser and fails to bind the component.
Q10MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript program:

```javascript
function createMultiplier(base) {
  let multiplier = base;

  function updateMultiplier(newValue) {
    multiplier = newValue;
    return multiplier;
  }

  function multiply(num) {
    return num * multiplier;
  }

  return {
    update: updateMultiplier,
    calculate: multiply,
    getMultiplier: function() { return multiplier; }
  };
}

const math1 = createMultiplier(3);
const math2 = createMultiplier(5);

console.log(math1.calculate(4));
console.log(math2.calculate(2));
console.log(math1.update(7));
console.log(math1.calculate(4));
console.log(math2.getMultiplier());
console.log(math1.getMultiplier());
```

What will be the output of the above program?
  1. 12, 10, 7, 12, 5, 7
  2. 12, 10, 7, 28, 5, 7
  3. 12, 10, 3, 28, 5, 3
  4. 15, 10, 7, 28, 7, 7
  5. 12, 10, 7, 21, 5, 7
Q11MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code snippet:

```javascript
var globalScore = 25;

const player1 = {
    score: 150,
    getScore: function() {
        return this.score;
    },
    displayScore: function(bonus) {
        return this.score + (bonus || 0);
    }
};

const player2 = { score: 200 };
const player3 = { score: 75 };

const method1 = player1.getScore;
const method2 = player1.getScore.bind(player2);
const method3 = player1.displayScore.bind(player3);

console.log(method1());
console.log(method2());
console.log(method3(50));
console.log(method3.call(player1, 25));
```

What will be the output of the above JavaScript code?
  1. undefined, 200, 125, 175
  2. 25, 200, 125, 175
  3. 150, 200, 125, 100
  4. 25, 200, 125, 100
  5. undefined, 200, 125, 100
Q12MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following JavaScript code to answer the below question:

```javascript
function normalFunc() {
  console.log(this.constructor.name);
}

const arrowFunc = () => {
  console.log(this.constructor.name);
};

const objj = {
  name: 'Test',
  normalMethod: normalFunc,
  arrowMethod: arrowFunc,
  outer: function () {
    return () => {
      console.log(this.name);
    };
  },
};

const inner = objj.outer();

objj.normalMethod();
objj.arrowMethod();
inner();
new arrowFunc();
```

Which of the following statements is/are TRUE?
  1. question figure
    text
    ```
    obj.normalMethod() prints "Object"
    ```
  2. question figure
    text
    obj.arrowMethod() prints "Window" or throws an error in strict mode
  3. question figure
    text
    inner() prints "Test"
  4. question figure
    text
    new arrowFunc() throws an error because arrow functions cannot be used as constructors
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q13MCQ3 marks
Which line of code should be changed to make this code work properly?
  1. question figure
    text
    ```html
    <input v-model="username"> should be
    replaced with <input v-bind="username">
    ```
  2. question figure
    text
    ```
    @click="loggedIn = true" should be
    replaced with v-on:click="login()"
    ```
  3. question figure
    text
    v-if="loggedIn" should be replaced
    with v-show="loggedIn"
  4. question figure
    text
    The code works correctly; no change is required.
Q14MCQ3 marks
question figure
Text of the picture (copyable)
If you wanted to make this app more
maintainable by moving logic to **methods**,
which line would you replace?
  1. question figure
    text
    Replace `@click="loggedIn = true"`
    with `@click="login"` and define a
    method
  2. question figure
    text
    Replace `<input v-model="username">`
    with `v-on:input="updateUsername"`
  3. question figure
    text
    Replace v-if="loggedIn" with
    v-else="loggedIn"
  4. question figure
    text
    This code is best, no changes required.
Comprehension passage - the questions below it refer to this
question figure
Q15MCQ3 marks
question figure
Text of the picture (copyable)
What classes will be applied to the
`<div>` initially (before any button
clicks)?
  1. btn, highlighted, btn-primary
  2. btn, btn-primary
  3. baseClass, btn-primary
  4. btn, highlighted, btn-primary, btn-disabled
Q16MCQ3 marks
question figure
Text of the picture (copyable)
What classes will be applied to the
`<div>` after clicking the "Toggle State"
button once?
  1. btn, highlighted
  2. btn, btn-disabled
  3. btn, highlighted, btn-disabled
  4. baseClass, highlighted, btn-disabled

Answer key

  1. Q1 (MCQ, 2 marks): C
  2. Q2 (MCQ, 2 marks): A
  3. Q3 (MCQ, 2 marks): B
  4. Q4 (MCQ, 2 marks): B
  5. Q5 (MCQ, 3 marks): D
  6. Q6 (MCQ, 3 marks): C
  7. Q7 (MCQ, 3 marks): B
  8. Q8 (MCQ, 4.5 marks): D
  9. Q9 (MCQ, 4.5 marks): B
  10. Q10 (MCQ, 4.5 marks): B
  11. Q11 (MCQ, 4.5 marks): E
  12. Q12 (MSQ, 3 marks): A, B, C, D
  13. Q13 (MCQ, 3 marks): D
  14. Q14 (MCQ, 3 marks): A
  15. Q15 (MCQ, 3 marks): B
  16. Q16 (MCQ, 3 marks): C

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Summary of Core Topics, Concepts, Principles, and Equations

Vue.js

  1. Reactivity in Vue 2

    • Vue 2 uses a virtual DOM to detect changes and update efficiently.
    • Modifications to data properties trigger reactivity, but direct index assignments (e.g., this.items[0] = 10) do not.
  1. Computed Properties

    • Computed properties are used for derived data that depends on other data properties.
    • They can have getters and setters.
    • Example:

      computed: {
        fullName() {
          return this.firstName + ' ' + this.lastName;
        }
      }
  1. Methods and Event Handling

    • Methods are used to handle events and perform actions.
    • Example:

      methods: {
        increment() {
          this.count++;
        }
      }
  1. Component Communication

    • Props are used to pass data from parent to child components.
    • Example:

      props: ['start']
  1. Conditional Rendering

    • v-if and v-show are used to conditionally render elements.
    • Example:

      <p v-if="loggedIn">Welcome, {{ username }}!</p>
  1. Class and Style Binding

    • Dynamic binding of classes and styles using :class and :style.
    • Example:

      <div :class="[baseClass, { highlighted: isHighlighted, 'btn-primary': isPrimary }]">

JavaScript

  1. Closures and Scope

    • Understanding of closures and how they capture variables from their lexical scope.
    • Example:

      function createFunctions() {
        var funcs = [];
        for (var i = 0; i < 3; i++) {
          funcs.push(function() {
            return i;
          });
        }
        return funcs;
      }
  1. Arrow Functions

    • Arrow functions do not have their own this context; they inherit this from the surrounding lexical context.
    • Example:

      const arrowFunc = () => {
        console.log(this.constructor.name);
      };
  1. Array Methods

    • Use of array methods like map, filter, sort, and forEach.
    • Example:

      products
        .filter((product) => product.price > 50)
        .map((product) => {
          return { ...product, priority: priorities[product.id] };
        })
        .sort((a, b) => a.priority - b.priority)
        .forEach((product) => {
          console.log(product.name);
        });
  1. Object Methods and this Context

    • Understanding of how this behaves in different contexts, especially in object methods and constructors.
    • Example:

      const obj = {
        name: 'Test',
        normalMethod: function() {
          console.log(this.name);
        },
        arrowMethod: () => {
          console.log(this.name);
        }
      };
  1. Bind, Call, and Apply

    • Use of bind, call, and apply to set the this context of functions.
    • Example:

      const method2 = player1.getScore.bind(player2);

HTML and CSS

  1. Template Syntax

    • Use of {{ }} for text interpolation and directives like v-model, v-if, and v-on.
    • Example:

      <input v-model="username">
      <button @click="loggedIn = true">Login</button>
  1. Dynamic Class Binding

    • Use of :class to dynamically bind classes based on data properties.
    • Example:

      <div :class="[baseClass, { highlighted: isHighlighted }]">