Question 1
On every component render
When one of its reactive dependencies changes
At fixed time intervals
Only when explicitly called

The IIT Madras BS Modern Application Development II (MAD 2) Quiz 2 paper sat on 16 Mar 2025, in the January 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.
On every component render
When one of its reactive dependencies changes
At fixed time intervals
Only when explicitly called
Correct answer
When one of its reactive dependencies changes
Use v-bind directly with a prop
Create a computed property with getter and setter
Use v-model with corresponding prop and emit
Modify the prop value directly in the child component
Correct answer
Use v-model with corresponding prop and emit
PWAs must be downloaded from an app store
PWAs only work on mobile devices
PWAs can work offline and be installed on the home screen
PWAs require native mobile code
Correct answer
PWAs can work offline and be installed on the home screen
Consider the below javascript program.
function testScope() { if (true) { var x = 10; let y = 20; } console.log(x); console.log(y);}testScope();What will be the output of the above program?
Correct answer
Consider the below javascript program.
let count = 0;
async function increment() { const incrementCount = () => { return new Promise(resolve => { setTimeout(() => { count++; resolve(count); }, 100); }); };
const results = await Promise.all([incrementCount(), incrementCount(),incrementCount()]); console.log(results);}
increment();console.log("Start");What will be the output of the above program?
Correct answer
Error
{ a: 1, b: 2 } undefined
{ a: 1, b: 2 } { a: 1, b: 2 }
1 undefined
1 { b: 2 }
Correct answer
1 { b: 2 }
Consider the below Vue router setup.
const Product = { template: `<div><h1>Product {{ $route.params.id }}</h1></div>`};
const ProductReviews = { template: `<div><h2>Reviews for Product</h2></div>`};
const routes = [ { path: '/products/:id', component: Product, children: [ { path: 'reviews', component: ProductReviews } ] }];
const router = new VueRouter({ routes});What will be the behavior when the user visits “/products/123/reviews”?
The Product component will be displayed with the id 123, and the ProductReviews component will be displayed as a child route.
The Product component will not display anything because the reviews path is incorrectly nested.
Only the ProductReviews component will be displayed, and the Product component will be ignored.
A 404 error will be shown because the /reviews route cannot be accessed as a child route.
Correct answer
The Product component will be displayed with the id 123, and the ProductReviews component will be displayed as a child route.
Consider the below Vuex setup.
const store = new Vuex.Store({ state: { cart: [ { id: 1, name: 'Item 1', price: 100 }, { id: 2, name: 'Item 2', price: 200 } ] }, getters: { totalPrice(state) { return state.cart.reduce((total, item) => total + item.price, 0); } }, mutations: { addToCart(state, item) { state.cart.push(item); } }, actions: { addItemToCart({ commit }, item) { commit('addToCart', item); } }});What will happen if the user dispatches the “addItemToCart” action to add a new item to the cart?
The total price will remain the same until the page is refreshed.
The total price will not reflect the new item because the getter is not reactive.
The total price will be updated immediately in the Vuex store.
A mutation error will occur because the cart array is not updated.
Correct answer
The total price will be updated immediately in the Vuex store.
Consider the following javascript code.
async function fetchData() { try { const response = await fetch('https://api.example.com/data'); if (!response.ok) throw new Error('HTTP error'); const data = await response.json(); return data; } catch (error) { if (error.name === 'TypeError') { return { status: 'network error' }; } return { status: 'http error' }; }}When the function is called what will be returned if the server is unreachable?
{ status: 'http error' }
{ status: 'network error' }
undefined
The promise will remain pending
Correct answer
{ status: 'network error' }
Consider the following javascript code.
function translateToEmoji(msg, dictionary, cb) { const translated = msg .split(' ') .map(word => dictionary[word] || word); cb(translated.join(' '));}
translateToEmoji('i love code', { heart: '🤎', code: '💻' }, result => console.log(result));What's logged?
Correct answer
Consider the following html with relevant vue cdn links added.
<div id="app"> <button @click="addLike">Like</button> <div>{{likes}}</div> </div> <script> new Vue({ el: '#app', data: () => ({ likes: 0, lastClick: 0 }), methods: { addLike() { if (Date.now() - this.lastClick < 500) { this.likes += 2; } else { this.likes += 1; } this.lastClick = Date.now(); }
} }) </script>If a user clicks rapidly twice (within 500ms), what will the likes count be?
1
2
3
4
Correct answer
3
Consider the following html with relevant vue cdn links added.
<div id="app"> <async-component ref="child"></async-component> <button @click="updateParent">Update Parent</button> </div>
<script> Vue.component('async-component', { template: '<div>{{message}}</div>', data() { return { message: 'Initial' } }, mounted() { setTimeout(() => { this.message = 'Updated in child' }, 0) } })
new Vue({ el: '#app', mounted() { this.$refs.child.message = 'Updated in parent' }, methods: { updateParent() { this.$refs.child.message = 'Button clicked' } } }) </script>In the Vue application above, what will be the initial rendered message?
"Initial"
"Updated in parent"
"Updated in child"
"Button clicked"
Correct answer
"Updated in child"
Consider the below javascript program.
const promiseChain = new Promise((resolve, reject) => { console.log('Step 1'); resolve(1); }) .then((value) => { console.log('Step 2:', value); return value + 1; }) .then((value) => { console.log('Step 3:', value); throw new Error('Error in Step 3'); }) .then((value) => { console.log('Step 4:', value); return value * 2; }) .catch((err) => { console.log('Caught:', err.message); return 5; }) .then((value) => { console.log('Step 5:', value); return value + 1; });
console.log('End of Code');What will be the output of the above program?
Step 1
Step 2: 1
Step 3: 2
Caught: Error in Step 3
End of Code
Step 1
Step 2: 1
Caught: Error in Step 3
Step 5: 5
End of Code
Step 1
Step 2: 1
Step 3: 2
End of Code
Step 1
End of Code
Step 2: 1
Step 3: 2
Caught: Error in Step 3
Step 5: 5
Correct answer
Step 1
End of Code
Step 2: 1
Step 3: 2
Caught: Error in Step 3
Step 5: 5
Consider the below Vue router setup.
Note: Assume that the API “/api/users/userId” is operational and returns the user’s data including name.
const UserProfile = { template: `<div><h2>User Profile</h2><p>{{ user.name }}</p></div>`, data() { return { user: {} }; }, created() { this.fetchUserData(); }, methods: { async fetchUserData() { const userId = this.$route.query.userId; const response = await fetch(`/api/users/${userId}`); this.user = await response.json(); } }};
const routes = [ { path: '/user', component: UserProfile }];
const router = new VueRouter({ routes});What will happen if the user navigates to “/user?userId=123”?
The component will display the user's name (fetched from API) correctly as expected.
The component will show because the API call will never be triggered.
The component will always show an empty profile because the userId query parameter is not reactive.
The component will throw an error because this.$route.query is not defined.
Correct answer
The component will display the user's name (fetched from API) correctly as expected.
Consider the below Vue.js application.
<template> <div> <button @click="goToPage('Home')">Go to Home</button> <button @click="goToPage('About')">Go to About</button> <button @click="goToPage('Contact')">Go to Contact</button>
<div v-if="visitedPages.length"> <h3>Visited Pages:</h3> <ul> <li v-for="(page, index) in visitedPages" :key="index">{{ page}}</li> </ul> </div> </div></template>
<script>export default { data() { return { visitedPages: [] }; }, mounted() { const storedPages = JSON.parse(sessionStorage.getItem('visitedPages'))|| []; this.visitedPages = storedPages; }, methods: { goToPage(page) { this.visitedPages.push(page); sessionStorage.setItem('visitedPages',JSON.stringify(this.visitedPages)); this.$router.push(`/${page.toLowerCase()}`); } }};</script>What will be the visited pages history when the user navigates between pages and refreshes the page?
The list of visited pages will reset to empty after the page is refreshed.
The list of visited pages will be updated with the current page after every navigation and will not reset even after reload.
The navigation history will not be stored in sessionStorage.
All of these
Correct answer
The list of visited pages will be updated with the current page after every navigation and will not reset even after reload.
Consider the below Vue.js application.
<template> <div> <input v-model="name" placeholder="Enter name"> <input v-model="email" placeholder="Enter email"> <button @click="submitForm">Submit</button> </div></template>
<script>export default { data() { return { name: '', email: '' }; }, mounted() { if (localStorage.getItem('formData')) { const savedData = JSON.parse(localStorage.getItem('formData')); this.name = savedData.name; this.email = savedData.email; } }, watch: { name(newVal) { localStorage.setItem('formData', JSON.stringify({ name: newVal, email:localStorage.email })); }, email(newVal) { localStorage.setItem('formData', JSON.stringify({ name: localStorage.name,email: newVal })); } }, methods: { submitForm() { localStorage.removeItem('formData'); this.name = ''; this.email = ''; } }};</script>What will happen if the user submits the form and reloads the page?
The form data will persist in the input fields even after submission and page reload.
The form data will be cleared after submission, and no data will appear after a page reload.
The form data will appear in the inputs after submission and page reload, but only until the user starts typing again.
The page will go blank.
Correct answer
The form data will be cleared after submission, and no data will appear after a page reload.