uiz Space

January 2025 term · Modern Application Development II · BSCS2006

Modern Application Development II Quiz 2: 16 March 2025 (January 2025 term)

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.

Questions
16
Marks
50
Duration
120 min
MCQ
16

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 16 Mar 2025 · No negative marking.

Question 1

+2 marksOne correct option
  1. A

    On every component render

  2. B

    When one of its reactive dependencies changes

  3. C

    At fixed time intervals

  4. D

    Only when explicitly called

Show answer

Correct answer

  • B

    When one of its reactive dependencies changes

Question 2

+2 marksOne correct option
  1. A

    Use v-bind directly with a prop

  2. B

    Create a computed property with getter and setter

  3. C

    Use v-model with corresponding prop and emit

  4. D

    Modify the prop value directly in the child component

Show answer

Correct answer

  • C

    Use v-model with corresponding prop and emit

Question 3

+2 marksOne correct option
  1. A

    PWAs must be downloaded from an app store

  2. B

    PWAs only work on mobile devices

  3. C

    PWAs can work offline and be installed on the home screen

  4. D

    PWAs require native mobile code

Show answer

Correct answer

  • C

    PWAs can work offline and be installed on the home screen

Question 4

+2 marksOne correct option

Consider the below javascript program.

javascript
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?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 5

+3 marksOne correct option

Consider the below javascript program.

javascript
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?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 6

+3 marksOne correct option
  1. A

    Error

  2. B

    { a: 1, b: 2 } undefined

  3. C

    { a: 1, b: 2 } { a: 1, b: 2 }

  4. D

    1 undefined

  5. E

    1 { b: 2 }

Show answer

Correct answer

  • E

    1 { b: 2 }

Question 7

+3 marksOne correct option

Consider the below Vue router setup.

javascript
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”?

  1. A

    The Product component will be displayed with the id 123, and the ProductReviews component will be displayed as a child route.

  2. B

    The Product component will not display anything because the reviews path is incorrectly nested.

  3. C

    Only the ProductReviews component will be displayed, and the Product component will be ignored.

  4. D

    A 404 error will be shown because the /reviews route cannot be accessed as a child route.

Show answer

Correct answer

  • A

    The Product component will be displayed with the id 123, and the ProductReviews component will be displayed as a child route.

Question 8

+3 marksOne correct option

Consider the below Vuex setup.

javascript
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?

  1. A

    The total price will remain the same until the page is refreshed.

  2. B

    The total price will not reflect the new item because the getter is not reactive.

  3. C

    The total price will be updated immediately in the Vuex store.

  4. D

    A mutation error will occur because the cart array is not updated.

Show answer

Correct answer

  • C

    The total price will be updated immediately in the Vuex store.

Question 9

+3 marksOne correct option

Consider the following javascript code.

javascript
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?

  1. A

    { status: 'http error' }

  2. B

    { status: 'network error' }

  3. C

    undefined

  4. D

    The promise will remain pending

Show answer

Correct answer

  • B

    { status: 'network error' }

Question 10

+3 marksOne correct option

Consider the following javascript code.

javascript
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?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 11

+3 marksOne correct option

Consider the following html with relevant vue cdn links added.

html
<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. A

    1

  2. B

    2

  3. C

    3

  4. D

    4

Show answer

Correct answer

  • C

    3

Question 12

+3 marksOne correct option

Consider the following html with relevant vue cdn links added.

html
<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?

  1. A

    "Initial"

  2. B

    "Updated in parent"

  3. C

    "Updated in child"

  4. D

    "Button clicked"

Show answer

Correct answer

  • C

    "Updated in child"

Question 13

+4.5 marksOne correct option

Consider the below javascript program.

javascript
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?

  1. A

    Step 1
    Step 2: 1
    Step 3: 2
    Caught: Error in Step 3
    End of Code

  2. B

    Step 1
    Step 2: 1
    Caught: Error in Step 3
    Step 5: 5
    End of Code

  3. C

    Step 1
    Step 2: 1
    Step 3: 2
    End of Code

  4. D

    Step 1
    End of Code
    Step 2: 1
    Step 3: 2
    Caught: Error in Step 3
    Step 5: 5

Show answer

Correct answer

  • D

    Step 1
    End of Code
    Step 2: 1
    Step 3: 2
    Caught: Error in Step 3
    Step 5: 5

Question 14

+4.5 marksOne correct option

Consider the below Vue router setup.

Note: Assume that the API “/api/users/userId” is operational and returns the user’s data including name.

javascript
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”?

  1. A

    The component will display the user's name (fetched from API) correctly as expected.

  2. B

    The component will show because the API call will never be triggered.

  3. C

    The component will always show an empty profile because the userId query parameter is not reactive.

  4. D

    The component will throw an error because this.$route.query is not defined.

Show answer

Correct answer

  • A

    The component will display the user's name (fetched from API) correctly as expected.

Question 15

+4.5 marksOne correct option

Consider the below Vue.js application.

html
<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?

  1. A

    The list of visited pages will reset to empty after the page is refreshed.

  2. B

    The list of visited pages will be updated with the current page after every navigation and will not reset even after reload.

  3. C

    The navigation history will not be stored in sessionStorage.

  4. D

    All of these

Show answer

Correct answer

  • B

    The list of visited pages will be updated with the current page after every navigation and will not reset even after reload.

Question 16

+4.5 marksOne correct option

Consider the below Vue.js application.

html
<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?

  1. A

    The form data will persist in the input fields even after submission and page reload.

  2. B

    The form data will be cleared after submission, and no data will appear after a page reload.

  3. C

    The form data will appear in the inputs after submission and page reload, but only until the user starts typing again.

  4. D

    The page will go blank.

Show answer

Correct answer

  • B

    The form data will be cleared after submission, and no data will appear after a page reload.