Quiz Space

September 2024 term · Modern Application Development II · BSCS2006

MAD 2 End Term: 22 December 2024, Set QDF3 (September 2024 term)

The IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 22 Dec 2024, in the September 2024 term, set QDF3: 32 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
32
Marks
100
Duration
180 min
MCQ
24
MSQ
8

Updated

Official paper: IIT M FOUNDATION DIPLOMA AN EXAM QDF3 22 Dec 2024 · No negative marking.

Question 1

+3 marksOne correct option
  1. A

    secure=False and samesite='Strict'

  2. B

    secure=True and samesite='None'

  3. C

    secure=True and samesite='Strict'

  4. D

    secure=False and samesite='Lax'

Show answer

Correct answer

  • C

    secure=True and samesite='Strict'

Question 2

+3 marksOne correct option

Which of the following is true regarding long polling?

  1. A

    Long polling opens multiple connections between the client and the server, and the server continuously sends updates to the client in real-time.

  2. B

    Long polling allows the client to make a single request to the server, where the server holds the connection open until new data is available and then sends the response.

  3. C

    Long polling involves the client repeatedly sending requests at fixed intervals to the server to check for updates, regardless of whether new data is available.

  4. D

    Long polling uses WebSockets to maintain a persistent, bidirectional connection between the client and the server.

Show answer

Correct answer

  • B

    Long polling allows the client to make a single request to the server, where the server holds the connection open until new data is available and then sends the response.

Question 3

+3 marksOne correct option

Given this Vue component structure:

javascript
Vue.component('child', {
template: `
<div>
<slot name="header" :info="info"></slot>
<slot :info="info"></slot>
</div>
`,
data() {
return {
info: { title: 'Hello', desc: 'World' }
}
}
})

Which slot usage is correct?

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

Correct answer

  • C

Question 4

+3 marksOne correct option

Consider the following JavaScript code snippet.

javascript
Promise.resolve(1)
.then(x => x + 1)
.then(x => Promise.resolve(x + 1))
.then(x => { throw 'error' })
.catch(e => e + 4)
.then(x => console.log(x))

What will be the output on the console?

  1. A

    7

  2. B

    error

  3. C

    undefined

  4. D

    error4

Show answer

Correct answer

  • D

    error4

Question 5

+3 marksOne correct option

Consider the following JavaScript code snippet.

javascript
async function test() {
console.log("Start");
const val = await Promise.resolve(5);
console.log(val);
return "End";
}
console.log("Begin");
test().then(data => console.log(data));
console.log("Finish");

What will be the output sequence?

  1. A

    Begin, Start, 5, End, Finish

  2. B

    Begin, Start, Finish, 5, End

  3. C

    Begin, Finish, Start, 5, End

  4. D

    Begin, Finish, Start, End, 5

Show answer

Correct answer

  • B

    Begin, Start, Finish, 5, End

Question 6

+3 marksOne correct option

What will happen if a page includes this CSP header and the script attempts to load an external JavaScript file from otherurl.com?

CSP Header:

text
Content-Security-Policy: default-src 'self';

HTML :

html
<script src="https://otherurl.com/code.js"></script>
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 7

+3 marksOne correct option

Consider the below Vue component.

html
<template>
<div>
<p v-if="isVisible">This paragraph is visible</p>
<p v-else>This paragraph is hidden</p>
</div>
</template>
<script>
export default {
data() {
return {
isVisible: true
};
}
};
</script>

What will happen when “this.isVisible = false” is executed?

  1. A

    The paragraph with the text “This paragraph is hidden” will be displayed.

  2. B

    The paragraph with the text “This paragraph is visible” will be displayed.

  3. C

    Both paragraphs will be displayed because of the v-if and v-else bindings.

  4. D

    No change will happen, since v-if and v-else do not update the DOM.

Show answer

Correct answer

  • A

    The paragraph with the text “This paragraph is hidden” will be displayed.

Question 8

+3 marksOne correct option

Consider the below JavaScript program.

javascript
console.log("Start");
setTimeout(function() {
console.log("Inside Timeout");
}, 0);
Promise.resolve().then(function() {
console.log("Inside Promise");
});
console.log("End");

What will be the output of the above program?

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

Correct answer

  • B

Question 9

+3 marksOne correct option

Consider the below JavaScript program.

javascript
function Person(name) {
this.name = name;
}
Person.prototype.greet = function() {
console.log("Hello, " + this.name);
};
const john = new Person("John");
john.greet();
delete john.greet;
john.greet();

What will be the output of the above program?

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

Correct answer

  • C

Question 10

+3 marksOne correct option

Given the following routes configured in Vue Router, assuming that routes have been correctly configured in vue router.

javascript
const routes = [
{ path: '/', component: Home },
{ path: '/profile/:userId', component: Profile },
{ path: '/settings', component: Settings },
{ path: '/settings/security', component: Security },
{ path: '*', component: NotFound },
];

Which route will match the path /settings/security?

  1. A

    Home

  2. B

    Profile

  3. C

    Security

  4. D

    Settings

Show answer

Correct answer

  • C

    Security

Question 11

+3 marksOne correct option

Consider the below Vue component.

javascript
export default {
data() {
return {
userName: '',
};
},
mounted() {
this.userName = sessionStorage.getItem('userName') || '';
},
watch: {
userName(newVal) {
sessionStorage.setItem('userName', newVal);
}
}
};

What will happen when the user enters a new value for “userName” and refreshes the page?

  1. A

    The new value will be stored in session storage, and the “userName” data property will be updated.

  2. B

    The new value will be stored in session storage, but the “userName” data property will be reset to an empty string on page refresh.

  3. C

    The “userName” data property will be reset to an empty string, and the session storage value will be ignored on refresh.

  4. D

    The “userName” data property will not be updated in session storage because session storage doesn't persist across refreshes.

Show answer

Correct answer

  • A

    The new value will be stored in session storage, and the “userName” data property will be updated.

Question 12

+3 marksOne correct option
  1. A

    II, III, I

  2. B

    III, I, II

  3. C

    III, II, I

  4. D

    I, II, III

Show answer

Correct answer

  • B

    III, I, II

Question 13

+2 marksOne correct option

Which of the following statements is FALSE?

  1. A

    Cache-Control: no-store prevents caching

  2. B

    Data stored in sessionStorage remains available even after the browser is closed and reopened.

  3. C

    ETag helps validate cache freshness

  4. D

    localStorage has larger storage limit than cookies

Show answer

Correct answer

  • B

    Data stored in sessionStorage remains available even after the browser is closed and reopened.

Question 14

+2 marksOne correct option

Which of the following statements is false when using the “async” and “await” keywords in JavaScript?

  1. A

    The “await” keyword can only be used inside an async function.

  2. B

    The async functions run synchronously, but their await statements execute asynchronously.

  3. C

    The “await” keyword pauses the execution of the surrounding async function until the promise resolves.

  4. D

    The async functions always return a promise, even if the return value is not a promise.

Show answer

Correct answer

  • B

    The async functions run synchronously, but their await statements execute asynchronously.

Question 15

+2 marksOne correct option

Consider the below JavaScript program.

javascript
const obj = {
name: "Abhi",
greet: function() {
console.log(this.name);
}
};
const greet = obj.greet;
greet();

What will be the output of the above program?

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

Correct answer

  • E

Question 16

+2 marksOne correct option

You have a Celery task send_email that needs to run every 10 minutes. How can you schedule it?

  1. A

    Using @app.task_periodic to run the task every 10 minutes.

  2. B

    Using @app.on_periodic to schedule a periodic task.

  3. C

    Using Celery Beat to schedule periodic tasks.

  4. D

    Celery doesn't support scheduling tasks at fixed intervals; you need to use an external scheduler.

Show answer

Correct answer

  • C

    Using Celery Beat to schedule periodic tasks.

Question 17

+4.5 marksOne correct option

Consider the following JavaScript code.

javascript
function addItemToCart(item) {
let cart = JSON.parse(localStorage.getItem('cart')) || [];
cart.push(item);
localStorage.setItem('cart', JSON.stringify(cart));
}
function getCartItems() {
return JSON.parse(localStorage.getItem('cart')) || [];
}
addItemToCart({ id: 1, name: 'Laptop' }.name);
console.log(getCartItems());

The above code is initially loaded on the browser and then the browser is refreshed two times. What will be the final output?

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

Correct answer

  • D

Question 18

+4.5 marksOne correct option

Given the following Vuex store setup.

javascript
const store = new Vuex.Store({
state: {
counter: 0
},
mutations: {
increment(state) {
state.counter++;
}
},
actions: {
async incrementAsync({ commit }) {
await new Promise(resolve => setTimeout(resolve, 1000));
commit('increment');
}
}
});

Assuming the store is correctly binded with a Vue app, what will be the correct behavior when the following code is executed?

javascript
this.$store.dispatch('incrementAsync');
  1. A

    The increment mutation will be called immediately after the dispatch.

  2. B

    The incrementAsync action will be executed synchronously, and increment will be committed before the promise resolves.

  3. C

    The state will be updated after the asynchronous operation completes.

  4. D

    The action will be skipped since mutations cannot be called inside actions.

Show answer

Correct answer

  • C

    The state will be updated after the asynchronous operation completes.

Question 19

+4.5 marksOne correct option

Consider the below Vue app.

javascript
new Vue({
el: '#app',
data: {
user: {
name: 'Abhi',
age: 30
}
},
watch: {
user: {
handler(newValue, oldValue) {
console.log('User object changed:', newValue);
},
deep: true
}
}
});

What will happen if the following code is executed?

app.user.name = “Dev”

  1. A

    The watcher will be triggered and log "User object changed: { name: 'Bob', age: 30 }".

  2. B

    The watcher will not be triggered because “name” is a nested property of “user” object.

  3. C

    The watcher will be triggered, but it will only log the new “name” value, i.e., “Dev”, and not the entire user object.

  4. D

    The watcher will throw an error because deep watching is not supported on nested objects.

Show answer

Correct answer

  • A

    The watcher will be triggered and log "User object changed: { name: 'Bob', age: 30 }".

Question 20

+4.5 marksOne correct option

Consider the following HTML, with included vue 2 cdn link.

html
<div id="app">{{doubledItems}}</div>
<script>
new Vue({
el: '#app',
data() {
return {
items: [1, 2, 3],
processed: []
};
},
computed: {
doubledItems() {
return this.items.map(x => x * 2);
}
},
created() {
this.processItems();
},
methods: {
processItems() {
this.items.push(4);
this.processed = this.doubledItems;
setTimeout(() => {
this.processed = this.processed.map(x =>
this.doubledItems.includes(x) ? x : x * 2
);
}, 0);
}
}
});
</script>

What will be displayed ?

  1. A

    [2, 4, 6]

  2. B

    [2, 4, 6, 8]

  3. C

    [4, 8, 12]

  4. D

    [2, 4, 6, 16]

Show answer

Correct answer

  • B

    [2, 4, 6, 8]

Question 21

+4.5 marksOne correct option

Consider the following html with appropriate vue 2 cdn link attached.

html
<div id="app"></div>
<script>
new Vue({
el: '#app',
template: `
<div>
<form @submit.prevent>
<input v-model="email" @input="validateEmail">
<button type="submit">Submit</button>
<p>Errors: {{ displayErrors.join(', ') }}</p>
</form>
</div>
`,
data() {
return {
email: '',
errors: [],
validating: false,
existingEmails: ['test@test.com',
'example@example.com']
};
},
computed: {
displayErrors() {
return this.validating ? ['Validating...'] :
this.errors;
},
},
methods: {
validateEmail() {
this.validating = true;
this.errors = [];
if (!this.email.includes('@')) {
this.errors.push('@ not present');
}
if (!this.email.includes('.')) {
this.errors.push('invalid format')
}
if (this.existingEmails.includes(this.email)) {
this.errors.push('Email exists');
}
this.validating = false;
},
},
watch: {
email(value) {
if (!value) this.errors = ['Required'];
},
},
});
</script>

When typing "test@test.com" and then deleting it all, what is shown in the "Errors" paragraph at the end?

  1. A

    Required

  2. B

    Invalid format, Email exists, Required

  3. C

    Required, Email exists

  4. D

    Validating..., Required

Show answer

Correct answer

  • A

    Required

Question 22

+4.5 marksOne correct option

Consider the following python code snippet. Assuming proper configuration for caching is done, answer the question below.

python
from flask import Flask, request
from flask_caching import Cache
import time
app = Flask(__name__)
app.config['CACHE_TYPE'] = 'RedisCache'
app.config['CACHE_DEFAULT_TIMEOUT'] = 5
cache = Cache(app)
@app.route('/time')
@cache.cached()
def get_time():
return str(time.time())

Suppose the following sequence of requests is made:
Request 1: GET /time at 00:00:00
Request 2: GET /time at 00:00:02
Request 3: GET /time at 00:00:06
What will the responses be for each request?

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

Correct answer

  • D

Question 23

+4.5 marksOne correct option

Consider the below Celery setup.

python
from celery import Celery
import time
app = Celery('tasks', broker='redis://localhost:6379/0')
@app.task
def long_task():
time.sleep(10)
return 'Task completed'

What will be the result of calling long_task.delay() (assuming more than 1 worker are available)?

  1. A

    The task will immediately execute and print the result 'Task completed'.

  2. B

    The task will execute asynchronously, and 'Task completed' will be printed after a 10-second delay.

  3. C

    The task will execute synchronously, blocking the main thread for 10 seconds.

  4. D

    None of these

Show answer

Correct answer

  • B

    The task will execute asynchronously, and 'Task completed' will be printed after a 10-second delay.

Question 24

+4.5 marksOne correct option

Consider the following Vue application with markup index.html and JavaScript file script.js.

File: index.html

html
<div id="app"></div>
<script src="script.js"></script>

File: script.js

javascript
new Vue({
el: '#app',
template: `<div>
Status: {{message}}<br>
ETA: {{ETA}}
</div>`,
data: {
message: "",
ETA: 10,
},
beforeCreate() {
this.message += "DOM Creating, "
this.ETA -= 1
},
created() {
this.message += "DOM Created, "
this.ETA -= 1
},
beforeMount() {
this.message += "DOM Mounting, "
this.ETA -= 1
},
mounted() {
this.message += "DOM Mounted"
this.ETA -= 1
},
})

Suppose the application is running on http://127.0.0.1:8080. What will be rendered by the browser?

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

Correct answer

  • C

Question 25

+2 marksOne or more correct options

Consider the below Vue router configuration.

javascript
const routes = [
{
path: '/user/:id',
component: UserProfile
}
];
const router = new VueRouter({
routes
});

Which of the following is a valid way to access the “id” parameter inside the UserProfile component?

Select all that apply.

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

Correct answers

  • C
  • D

Question 26

+2 marksOne or more correct options

Which of the following statements are true about Lighthouse?

Select all that apply.

  1. A

    Lighthouse measures various performance metrics, including Time to Interactive and Speed Index.

  2. B

    Lighthouse generates a single score for UI design only.

  3. C

    It can emulate network throttling and device types during performance evaluation.

  4. D

    Lighthouse focuses exclusively on performance and ignores accessibility.

Show answer

Correct answers

  • A

    Lighthouse measures various performance metrics, including Time to Interactive and Speed Index.

  • C

    It can emulate network throttling and device types during performance evaluation.

Question 27

+2 marksOne or more correct options

Which of the following statement(s) is/are correct regarding the behavior of local storage in Vue.js applications?

Select all that apply.

  1. A

    The local storage data persists even after the browser is closed and reopened.

  2. B

    The local storage data is automatically cleared every session.

  3. C

    The local storage can only store strings, and storing objects requires manual serialization and de-serialization.

  4. D

    Vue's reactivity system automatically updates the local storage when bound to a Vue data property.

Show answer

Correct answers

  • A

    The local storage data persists even after the browser is closed and reopened.

  • C

    The local storage can only store strings, and storing objects requires manual serialization and de-serialization.

Question 28

+2 marksOne or more correct options

Select all that apply.

  1. A

    The class, namely “classB” will always be applied to the div element.

  2. B

    The classes, namely “classA” and “classB” will always be applied to the div element.

  3. C

    The class, namely “classA” will only be applied to the div element, if the variable “isClassA” evaluates to true.

  4. D

    The class, namely “classB” will only be applied to the div element, if no variable with name “isClassA” exists.

Show answer

Correct answers

  • A

    The class, namely “classB” will always be applied to the div element.

  • C

    The class, namely “classA” will only be applied to the div element, if the variable “isClassA” evaluates to true.

Question 29

+3 marksOne or more correct options

Which of the following statements correctly describe the use of asynchronous messaging systems and frameworks?

Select all that apply.

  1. A

    Celery allows web servers to offload long-running tasks to worker processes, decoupling task execution from user requests.

  2. B

    Push queues are used for real-time operations, while pull queues are better suited for batch processing.

  3. C

    Server-Sent Events (SSE) provide a persistent connection between server and client, enabling bi-directional communication.

  4. D

    Redis is a high-performance in-memory database that supports Pub/Sub.

Show answer

Correct answers

  • A

    Celery allows web servers to offload long-running tasks to worker processes, decoupling task execution from user requests.

  • B

    Push queues are used for real-time operations, while pull queues are better suited for batch processing.

  • D

    Redis is a high-performance in-memory database that supports Pub/Sub.

Question 30

+3 marksOne or more correct options

Which of the following statement(s) is/are true about Webhooks?

Select all that apply.

  1. A

    A Webhook is a method for a server to send real-time data to another server as an HTTP POST request.

  2. B

    Webhooks are typically used for sending periodic updates at regular intervals.

  3. C

    A client must continuously poll a Webhook URL to receive data.

  4. D

    Webhooks are usually used in event-driven architectures, where an event triggers an HTTP POST request to a specified endpoint.

Show answer

Correct answers

  • A

    A Webhook is a method for a server to send real-time data to another server as an HTTP POST request.

  • D

    Webhooks are usually used in event-driven architectures, where an event triggers an HTTP POST request to a specified endpoint.

Question 31

+3 marksOne or more correct options

Which of the following statement(s) is/are true regarding Server-Sent Events (SSE) and WebSockets?

Select all that apply.

  1. A

    SSE is a two-way communication protocol, while WebSockets are
    unidirectional.

  2. B

    WebSockets are more suited for scenarios requiring bi-directional communication.

  3. C

    SSE is based on HTTP and can only be used for server-to-client communication, while WebSockets are based on TCP and support both directions.

  4. D

    SSE is an extension of WebSockets, providing enhanced support for server-to- client communication.

Show answer

Correct answers

  • B

    WebSockets are more suited for scenarios requiring bi-directional communication.

  • C

    SSE is based on HTTP and can only be used for server-to-client communication, while WebSockets are based on TCP and support both directions.

Question 32

+3 marksOne or more correct options

Which of the following is/are typical use case(s) for Celery tasks?

Select all that apply.

  1. A

    Processing time-consuming or resource-intensive background jobs asynchronously.

  2. B

    Directly handling incoming HTTP requests in web servers.

  3. C

    Scheduling periodic tasks like sending emails or cleaning up the database.

  4. D

    Serving real-time notifications over WebSockets.

Show answer

Correct answers

  • A

    Processing time-consuming or resource-intensive background jobs asynchronously.

  • C

    Scheduling periodic tasks like sending emails or cleaning up the database.