Question 1
In Vue 2, what happens when you update a data property?
DOM is immediately updated without virtual DOM
The page reloads
The virtual DOM detects changes and updates efficiently
A full component re-renders from scratch

The IIT Madras BS Modern Application Development II (MAD 2) Quiz 1 paper sat on 13 Jul 2025, in the May 2025 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
In Vue 2, what happens when you update a data property?
DOM is immediately updated without virtual DOM
The page reloads
The virtual DOM detects changes and updates efficiently
A full component re-renders from scratch
Correct answer
The virtual DOM detects changes and updates efficiently
Consider the following HTML, with the correct Vue 2 CDN links included:
Html code.
<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:
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?
Items: 2, Total Cost: $30, Status: Few Items
Items: 2, Total Cost: $45, Status: Few Items
Items: 3, Total Cost: $30, Status: Full Cart
Items: 2, Total Cost: $30, Status: Full Cart
Items: 1, Total Cost: $15, Status: Few Items
Correct answer
Items: 2, Total Cost: $30, Status: Few Items
Consider the following code.
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, 2, 3]
[10, 40, 90]
[10, 20, 30]
[NaN, NaN, NaN]
Correct answer
[10, 40, 90]
this.items.push(4)
this.items[0] = 10
this.items = [10, 2, 3]
this.obj.a = 2
Correct answer
this.items[0] = 10
What will be the output of this code?
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]());0, 1, 2
1, 2, 3
undefined, undefined, undefined
3, 3, 3
Correct answer
3, 3, 3
Which computed property implementation is INCORRECT?
Correct answer
Consider the following JavaScript code:
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?
Correct answer
Consider the following JavaScript code to answer the below question:
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?
Correct answer
Consider the following Vue.js (Vue 2) code to answer the following question:
<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?
Correct answer
Consider the following JavaScript program:
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?
12, 10, 7, 12, 5, 7
12, 10, 7, 28, 5, 7
12, 10, 3, 28, 5, 3
15, 10, 7, 28, 7, 7
12, 10, 7, 21, 5, 7
Correct answer
12, 10, 7, 28, 5, 7
Consider the following JavaScript code snippet:
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?
undefined, 200, 125, 175
25, 200, 125, 175
150, 200, 125, 100
25, 200, 125, 100
undefined, 200, 125, 100
Correct answer
undefined, 200, 125, 100
Consider the following JavaScript code to answer the below question:
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?
Correct answers
You're building a basic Vue app using Vue 2 via CDN to show a user's login form.
You want to:
v-model.But this code is yet to be tested, you have to test this code and push it to production.
<body>
<div id="app"> <input v-model="username"> <button @click="loggedIn = true">Login</button>
<p v-if="loggedIn"> Welcome, {{ username }}! </p></div>
<script> new Vue({ el: '#app', data: { username: '', loggedIn: false } });</script>
</body></html>Based on the above data, answer the given subquestions.
Which line of code should be changed to make this code work properly?
Correct answer
You're building a basic Vue app using Vue 2 via CDN to show a user's login form.
You want to:
v-model.But this code is yet to be tested, you have to test this code and push it to production.
<body>
<div id="app"> <input v-model="username"> <button @click="loggedIn = true">Login</button>
<p v-if="loggedIn"> Welcome, {{ username }}! </p></div>
<script> new Vue({ el: '#app', data: { username: '', loggedIn: false } });</script>
</body></html>Based on the above data, answer the given subquestions.
Correct answer
Consider the following HTML with relevant Vue 2 CDN link attached and answer the given subquestions.
Html file:
<div id="app"> <div :class="[baseClass, { highlighted: isHighlighted, 'btn-primary': isPrimary, 'btn-disabled': !isEnabled }]"> {{ buttonText }} </div> <button @click="toggleState">Toggle State</button></div>script
const app = new Vue({ el: '#app', data: { buttonText: 'Click Me', baseClass: 'btn', isHighlighted: false, isPrimary: true, isEnabled: true }, methods: { toggleState() { this.isHighlighted = !this.isHighlighted; this.isPrimary = !this.isPrimary; this.isEnabled = !this.isEnabled; } }})btn, highlighted, btn-primary
btn, btn-primary
baseClass, btn-primary
btn, highlighted, btn-primary, btn-disabled
Correct answer
btn, btn-primary
Consider the following HTML with relevant Vue 2 CDN link attached and answer the given subquestions.
Html file:
<div id="app"> <div :class="[baseClass, { highlighted: isHighlighted, 'btn-primary': isPrimary, 'btn-disabled': !isEnabled }]"> {{ buttonText }} </div> <button @click="toggleState">Toggle State</button></div>script
const app = new Vue({ el: '#app', data: { buttonText: 'Click Me', baseClass: 'btn', isHighlighted: false, isPrimary: true, isEnabled: true }, methods: { toggleState() { this.isHighlighted = !this.isHighlighted; this.isPrimary = !this.isPrimary; this.isEnabled = !this.isEnabled; } }})btn, highlighted
btn, btn-disabled
btn, highlighted, btn-disabled
baseClass, highlighted, btn-disabled
Correct answer
btn, highlighted, btn-disabled