Question 1
Which of the following Vue 2 template syntaxes are valid?

The IIT Madras BS Modern Application Development II (MAD 2) Quiz 1 paper sat on 26 Oct 2025, in the September 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.
Which of the following Vue 2 template syntaxes are valid?
Correct answers
Which of the following statements about Vue 2 templates are correct?
v-if removes elements from DOM when false
v-show toggle initiates re-render of the Vue component
v-bind can bind attributes and class dynamically
Vue 2 templates must use double curly braces for all text interpolation
Correct answers
v-if removes elements from DOM when false
v-bind can bind attributes and class dynamically
Consider the following JavaScript code:
let employees = [ { name: "Rahul", age: 28 }, { name: "Priya", age: 24 }, { name: "Amit", age: 32 }];employees.sort((a, b) => a.age - b.age);console.log(employees.map(e => e.name).join(" - "));What will be printed on the console?
Rahul - Priya - Amit
Priya - Rahul - Amit
Amit - Rahul - Priya
Priya - Amit - Rahul
Correct answer
Priya - Rahul - Amit
Consider the following JavaScript code snippet.
const users = [ { name: "Amit", age: 25 }, { name: "Bhavna", age: 20 }, { name: "Chirag", age: 30 },];
const names = users .filter((u) => u.age >= 25) .map((u) => u.name.toUpperCase()) .sort();
console.log(JSON.stringify(names));What is logged on the console?
['Amit', 'Chirag']
['CHIRAG', 'AMIT']
['AMIT', 'CHIRAG']
['AMIT', 'Bhavna', 'CHIRAG']
Correct answer
['AMIT', 'CHIRAG']
Consider the following JavaScript code snippet.
let subject = "Dog";
function camera() { let subject = "Deer"; function click() { console.log(`clicked picture of ${subject}`); } subject = "Cat"; return click;}
let cameraPicture = camera();cameraPicture();What is logged to the console?
clicked picture of Dog
clicked picture of Deer
clicked picture of Cat
clicked picture of undefined
Correct answer
clicked picture of Cat
1-C, 2-D, 3-A, 4-E, 5-B
1-A, 2-C, 3-B, 4-D, 5-E
1-C, 2-A, 3-D, 4-B, 5-E
1-E, 2-A, 3-D, 4-C, 5-B
Correct answer
1-C, 2-A, 3-D, 4-B, 5-E
Consider the following HTML, with the correct Vue 2 CDN links included
<body> <div id="app"> <p>Coffee</p> <button @click="orderCoffee">Order</button> <p>Total Cost: {{totalCost}}</p> <p>Order Count: {{orderCount}}</p> </div> <script> new Vue({ el: '#app', data() { return { totalCost: '0', unitPrice: 25, orderCount: 0 } }, methods: { orderCoffee() { this.totalCost += this.unitPrice; this.orderCount++; } } }) </script></body>What will be displayed for "Total Cost" and "Order Count" when the Order button is clicked three times?
Correct answer
Consider this nested loop is written in JavaScript:
let result = "";for (let i = 0; i < 2; i++) { for (var j = 0; j < 2; j++) { result += i + j; }}console.log(result);Which of the following statements is/are true?
Correct answers
Consider the following HTML and JavaScript code.
HTML file
<button id="btn">Click Me</button>
<script> const btn = document.getElementById('btn'); btn.addEventListener('click', () => console.log('A')); btn.onclick = () => console.log('B'); btn.addEventListener('click', () => console.log('C')); btn.click();</script>Among the following console log statements, which ones will be logged when the code executes?
(Select all that apply, irrespective of the order.)
A
B
C
None
Correct answers
A
B
C
Consider the following HTML and JavaScript, assume Vue 2 CDN link to be already included.
index.html:
<div id="app"> <p v-for="n in numbers">{{ n }}</p></div><script src="app.js" />app.js:
var app = new Vue({ el: "#app", data: { numbers: [1, 2, 3] },});
app.data.numbers.push(4);How many <p> elements will be rendered?
Correct answer: 3
Consider the following JavaScript code snippet:
const products = [ { name: 'Laptop', price: 1200, category: 'Electronics', inStock: true }, { name: 'Book', price: 25, category: 'Education', inStock: false }, { name: 'Phone', price: 800, category: 'Electronics', inStock: true }, { name: 'Pen', price: 5, category: 'Stationery', inStock: true }, { name: 'Tablet', price: 600, category: 'Electronics', inStock: false }];
const result = products .filter(item => item.category === 'Electronics' && item.inStock) .map(item => ({ ...item, discountedPrice: item.price * 0.9 })) .filter(item => item.discountedPrice > 500);
console.log(result.length);console.log(result[0].name);What will be the output of the above code on the browser's console?
Correct answer
Consider the below JavaScript program:
const globalVar = 50;
const object1 = { globalVar: 100, method1: function() { console.log(globalVar, this.globalVar); return () => { console.log(globalVar, this.globalVar); } }}
const object2 = { globalVar: 200, method2: () => { console.log(globalVar, this.globalVar); return function() { console.log(globalVar, this.globalVar); } }}
const fn1 = object1.method1();fn1();const fn2 = object2.method2();fn2();What will be the output of the above program on the browser's console, if executed?
Correct answer
Consider the following JavaScript code:
class Region { constructor(region) { this.region = region; } describe() { return `${this.region} is a region.`; }}
class Country extends Region { constructor(region, name) { super(region); this.name = name; } describe() { return `${this.name} is in ${this.region}.`; }}
let r = new Region("Asia");let c = new Country("Europe", "Germany");let f = c.describe;Which of the following statements are true?
Correct answers
Correct answers
Read the Vue.js code and answer the given subquestions. The parent binds an input with v-model and passes the value as a prop to a child component; the child contains a named slot that shows the message in uppercase.
<div id="app"> <p>{{ message }}</p> <input v-model="message" /> <child-component :title="message"> <template slot="header"> <h3>{{ message.toUpperCase() }}</h3> </template> </child-component></div>
<script>Vue.component('child-component', { props: ['title'], template: ` <div> <h2>{{ title }}</h2> <slot name="header"></slot> <p>Child Content</p> </div> `});
new Vue({ el: '#app', data: { message: 'Hello Vue' }});</script>Correct answer
Read the Vue.js code and answer the given subquestions. The parent binds an input with v-model and passes the value as a prop to a child component; the child contains a named slot that shows the message in uppercase.
<div id="app"> <p>{{ message }}</p> <input v-model="message" /> <child-component :title="message"> <template slot="header"> <h3>{{ message.toUpperCase() }}</h3> </template> </child-component></div>
<script>Vue.component('child-component', { props: ['title'], template: ` <div> <h2>{{ title }}</h2> <slot name="header"></slot> <p>Child Content</p> </div> `});
new Vue({ el: '#app', data: { message: 'Hello Vue' }});</script>Correct answers