Quiz Space

May 2024 term · Modern Application Development II · BSCS2006

MAD 2 End Term: 1 September 2024 (May 2024 term)

The IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 1 Sept 2024, in the May 2024 term: 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 FN EXAM QDF1 01 Sep 2024 · No negative marking.

Question 1

+2 marksOne correct option

What of the following is the primary objective of a CSRF token?

  1. A

    To encrypt the user's session

  2. B

    To validate that the request comes from the authenticated user

  3. C

    To store the user's password securely

  4. D

    To compress the HTTP request

Show answer

Correct answer

  • B

    To validate that the request comes from the authenticated user

Question 2

+2 marksOne correct option

Suppose an application is being loaded from the origin https://example.com. Which of the following origins will the browser allow while making a fetch call, by default?

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

Correct answer

  • D

Question 3

+2 marksOne correct option

What is the correct sequence of steps to update the state in Vuex when handling an asynchronous operation?

  1. A

    State → Dispatch an action → Commit a mutation → State change

  2. B

    Dispatch an action → Commit a mutation → State change

  3. C

    Commit a mutation → Dispatch an action → State change

  4. D

    State change → Commit a mutation → Dispatch an action

Show answer

Correct answer

  • B

    Dispatch an action → Commit a mutation → State change

Question 4

+3 marksOne correct option

Suppose you are developing an application for millions of users that will perform intensive data analysis and return the results asynchronously. Arrange the following set of actions/operations to achieve an efficient and scalable design.
I) Save the result to a database
II) Invoke a callback URL
III) Queue the analysis job

  1. A

    II, I, III

  2. B

    III, I, II

  3. C

    III, II, I

  4. D

    I, II, III

Show answer

Correct answer

  • B

    III, I, II

Question 5

+3 marksOne correct option

Which of the following statements about Redis is true?

  1. A

    Redis is a relational database that uses SQL for querying data.

  2. B

    Redis is an in-memory data structure store, commonly used as a database, cache, and message broker.

  3. C

    Redis can only store string data types and does not support complex data structures like lists or sets.

  4. D

    Redis cannot handle numerous operations per second.

Show answer

Correct answer

  • B

    Redis is an in-memory data structure store, commonly used as a database, cache, and message broker.

Question 6

+3 marksOne correct option

Which of the following scenarios is an example of a Cross-Site Request Forgery (CSRF) attack?

  1. A

    A user receives an email containing a link to a phishing site that asks for their login credentials.

  2. B

    A user clicks on a malicious link while logged into their bank account, and without their knowledge, a money transfer request is sent to the bank's server using the user's authenticated session.

  3. C

    A hacker uses a brute-force attack to guess the password of a user's online account.

  4. D

    A user is tricked into downloading and installing malware that steals their sensitive information.

Show answer

Correct answer

  • B

    A user clicks on a malicious link while logged into their bank account, and without their knowledge, a money transfer request is sent to the bank's server using the user's authenticated session.

Question 7

+3 marksOne correct option

Match the following technologies with their typical use cases:

  1. A

    1 - C, 2 - A, 3 - D, 4 - B, 5 - E

  2. B

    1 - D, 2 - E, 3 - A, 4 - C, 5 - B

  3. C

    1 - C, 2 - C, 3 - E, 4 - A, 5 - D

  4. D

    1 - D, 2 - A, 3 - C, 4 - D, 5 - B

Show answer

Correct answer

  • A

    1 - C, 2 - A, 3 - D, 4 - B, 5 - E

Question 8

+3 marksOne correct option

Consider the below javascript program.

javascript
function parent() {
var a = 1;
function child() {
console.log(a);
}
a = 2;
return child;
}
var closure = parent();
closure();

What will be the output of the above program, if executed?

  1. A

    2

  2. B

    1

  3. C

    undefined

  4. D

    Error

Show answer

Correct answer

  • A

    2

Question 9

+3 marksOne correct option

Consider the following JavaScript code snippet.

javascript
// Code Snippet 1
sessionStorage.setItem('username', 'course_user');
let storedUsername = sessionStorage.getItem('username');
// Code Snippet 2
sessionStorage.removeItem('username');
let removedUsername = sessionStorage.getItem('username');
// Code Snippet 3
sessionStorage.clear();
let clearedStorage = sessionStorage.username;

What will be the values of 'storedUsername', 'removedUsername', and 'clearedStorage' after the execution of the above code snippets?

  1. A

    storedUsername: 'course_user', removedUsername: null, clearedStorage: null

  2. B

    storedUsername: 'course_user', removedUsername: undefined,
    clearedStorage: null

  3. C

    storedUsername: 'course_user', removedUsername: null, clearedStorage: undefined

  4. D

    storedUsername: 'course_user', removedUsername: undefined,
    clearedStorage: undefined

Show answer

Correct answer

  • C

    storedUsername: 'course_user', removedUsername: null, clearedStorage: undefined

Question 10

+3 marksOne correct option

Consider the following javascript code

javascript
const obj = {
num: 40,
regularFunction: function() {
return this.value;
},
arrowFunction: () => {
return this.value;
}
};
const regularResult = obj.regularFunction();
const arrowResult = obj.arrowFunction();

What are the values of regularResult and arrowResult?

  1. A

    regularResult = 40, arrowResult = 40

  2. B

    regularResult = undefined, arrowResult = undefined

  3. C

    regularResult = 40, arrowResult = undefined

  4. D

    regularResult = undefined, arrowResult = 40

Show answer

Correct answer

  • C

    regularResult = 40, arrowResult = undefined

Question 11

+3 marksOne correct option

Consider the below 2 approaches:

Approach 1:

html
<script>
setInterval(() => document.title = "Title A", 2000)
setInterval(() => document.title = "Title B", 1000)
</script>

Approach 2:

html
<script>
setInterval(() => document.title = "Title A", 1000)
setInterval(() => document.title = "Title B", 2000)
</script>

Choose the correct statement:

  1. A

    The approach 1 will toggle the page title between “Title A” and “Title B” after every 1 second (approx).

  2. B

    The approach 2 will toggle the page title between “Title A” and “Title B” after every 1 second (approx).

  3. C

    None of the approaches will toggle the page title after every 1 second.

  4. D

    None of these

Show answer

Correct answer

  • C

    None of the approaches will toggle the page title after every 1 second.

Question 12

+3 marksOne correct option

Consider the below JavaScript program.

html
<script>
for (var i = 0; i <= 3; i++) {
setTimeout(() => console.log(i), (i+1)*1500);
}
</script>

What will be the output of the above program, if executed? Also, predict the minimum number of seconds the program will take to complete the execution?

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

Correct answer

  • D

Question 13

+3 marksOne or more correct options

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

Select all that apply.

  1. A

    Webhooks use HTTP requests to communicate events from one service to another.

  2. B

    Webhooks require the recipient service to periodically poll the sender for updates.

  3. C

    Webhooks are typically implemented using HTTP POST requests.

  4. D

    Webhooks guarantee that events will be delivered in order and exactly once.

Show answer

Correct answers

  • A

    Webhooks use HTTP requests to communicate events from one service to another.

  • C

    Webhooks are typically implemented using HTTP POST requests.

Question 14

+3 marksOne or more correct options

Which of the following statement(s) is/are true regarding javascript?

Select all that apply.

  1. A

    Function declarations are hoisted along with their definitions.

  2. B

    Variable declarations with var are hoisted with their initializations.

  3. C

    let and const declarations are hoisted to the top of their block but remain uninitialized until execution reaches the declaration.

  4. D

    Only function declarations are hoisted, not function definition.

Show answer

Correct answers

  • A

    Function declarations are hoisted along with their definitions.

  • C

    let and const declarations are hoisted to the top of their block but remain uninitialized until execution reaches the declaration.

Question 15

+3 marksOne or more correct options

Which of the following scenarios are best suited for using Celery tasks?

Select all that apply.

  1. A

    Handling real-time user interactions on a website.

  2. B

    Sending out periodic email notifications to users.

  3. C

    Generating and displaying dynamic content on a web page.

  4. D

    Performing long-running data processing tasks in the background.

Show answer

Correct answers

  • B

    Sending out periodic email notifications to users.

  • D

    Performing long-running data processing tasks in the background.

Question 16

+3 marksOne or more correct options

Which of the following statements is/are true regarding webhooks and server sent events (SSE)?

Select all that apply.

  1. A

    Webhooks are typically used for server-to-server communication, while SSE is used for server-to-client communication.

  2. B

    Webhooks require the client to maintain an open connection to receive updates, while SSE does not.

  3. C

    Webhooks are initiated by the server, while SSE connections are initiated by the client.

  4. D

    SSE supports bidirectional communication, whereas webhooks do not.

Show answer

Correct answers

  • A

    Webhooks are typically used for server-to-server communication, while SSE is used for server-to-client communication.

  • C

    Webhooks are initiated by the server, while SSE connections are initiated by the client.

Question 17

+3 marksOne or more correct options

Which of the following is/are the correct ways to achieve the following.
1. Always apply class named “errorClass”,
2. The class named “activeClass” should only be applied when the Vue data variable “isActive” is truthy

Select all that apply.

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

Correct answers

  • A
  • D

Question 18

+2 marksOne or more correct options

Which of the following is/are true about Server-Sent Events (SSE)?

Select all that apply.

  1. A

    SSE connections are established using HTTP.

  2. B

    SSE supports bidirectional communication between client and server.

  3. C

    SSE automatically switches to web socket if the connection is successful.

  4. D

    SSE is suitable for sending updates to multiple clients simultaneously.

Show answer

Correct answers

  • A

    SSE connections are established using HTTP.

  • D

    SSE is suitable for sending updates to multiple clients simultaneously.

Question 19

+2 marksOne or more correct options

Which of the following HTTP header(s) can be used to control caching behavior in web applications?

Select all that apply.

  1. A

    Cache-Control

  2. B

    Expires

  3. C

    Bearer

  4. D

    Content-Type

Show answer

Correct answers

  • A

    Cache-Control

  • B

    Expires

Question 20

+2 marksOne or more correct options

Which of the following statement(s) is/are true regarding long and short polling?

Select all that apply.

  1. A

    A webhook is the same as short polling.

  2. B

    The short polling can be used to know the state of an asynchronous task, and trigger an action if the task gets completed.

  3. C

    The long polling cannot be achieved using HTTP protocol.

  4. D

    Long Polling can be used to achieve real time communication.

Show answer

Correct answers

  • B

    The short polling can be used to know the state of an asynchronous task, and trigger an action if the task gets completed.

  • D

    Long Polling can be used to achieve real time communication.

Question 21

+4.5 marksOne correct option

Consider the following Vue.js 2 component using CDN.

html
<div id="app">
<input v-model="newItem" placeholder="Add an item" />
<button @click="addItem">Add</button>
<ul>
<li v-for="(item, index) in items" :key="index">
{{ index + 1 }}. {{ item }}
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script>
new Vue({
el: '#app',
data: {
newItem: '',
items: ['Apple', 'Banana']
},
methods: {
addItem() {
if (this.newItem) {
this.items.push(this.newItem, this.newItem);
this.newItem = '';
}
}
}
});
</script>

After entering "Orange" in the input box and clicking the "Add" button, what will be seen in the browser?

  1. A

    1. Apple
    2. Banana
    3. Orange
    4. Orange

  2. B

    1. Apple
    2. Banana
    3. Orange

  3. C

    1. Apple
    2. Banana
    3. Orange
    3. Orange

  4. D

    1. Apple
    2. Banana

Show answer

Correct answer

  • A

    1. Apple
    2. Banana
    3. Orange
    4. Orange

Question 22

+4.5 marksOne correct option

Consider the following javascript code running on browser

javascript
localStorage.setItem('counter', '0');
sessionStorage.setItem('total', '5');
for (let i = 0; i < 3; i++) {
let counter = localStorage.getItem('counter');
let total = sessionStorage.getItem('total');
counter += 2;
total *= 2;
localStorage.setItem('counter', counter);
sessionStorage.setItem('total', total);
}
sessionStorage.clear();
console.log(localStorage.getItem('counter'));
console.log(sessionStorage.getItem('total'));

What will be the output in the browser console?

  1. A

    6
    40

  2. B

    null
    40

  3. C

    6
    null

  4. D

    0222
    null

Show answer

Correct answer

  • D

    0222
    null

Question 23

+4.5 marksOne correct option

Consider the below JavaScript program.

javascript
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name} barks`);
}
}
const d = new Dog('Rex');
d.speak();
console.log(d.__proto__ === Dog.prototype);
console.log(d.__proto__.__proto__ === Animal.prototype);

What will be the output of the above program?

  1. A

    Rex barks
    true
    true

  2. B

    Rex barks
    false
    true

  3. C

    Rex barks.
    true
    false

  4. D

    Rex barks.
    false
    false

Show answer

Correct answer

  • A

    Rex barks
    true
    true

Question 24

+4.5 marksOne correct option

Consider the below flask application.

python
from flask import Flask
from flask_caching import Cache
from time import sleep
config = {
"CACHE_TYPE": "SimpleCache",
"CACHE_DEFAULT_TIMEOUT": 180
}
app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
@cache.memoize(timeout=180)
def get_data(param):
sleep(5)
return f"Data for {param}"
@app.route('/data/<param>')
def data(param):
result = get_data(param)
return f"Result: {result}"
if __name__ == '__main__':
app.run(debug=True)

If the application is running on “http://127.0.0.1:5000” and the user visits the URL “http://127.0.0.1:5000/data/test” three times in the following sequence:

1. First visit
2. Second visit after 2 minutes and 30 seconds
3. Third visit after 1 minute from the second visit
What will be the approximate difference in response times between the first and third requests?

  1. A

    5 seconds

  2. B

    0 seconds

  3. C

    10 seconds

  4. D

    180 seconds

Show answer

Correct answer

  • B

    0 seconds

Question 25

+4.5 marksOne correct option

Consider the below JavaScript program.

javascript
new Promise((resolve, reject) => {
const num = 0.6;
if (num > 0.5) {
resolve(num);
} else {
reject(num);
}
})
.then(data => {
console.log("Step 1:", data);
if (data > 0.75) {
return data * 2;
} else {
return Promise.reject(new Error("Less than 0.75"));
}
})
.then(data => {
console.log("Step 2:", data);
return data + 5;
})
.catch(error => {
console.log("Step 3:", error.message);
if (error.message === "Less than 0.75") {
return 1;
} else {
throw error;
}
javascript
})
.then(data => {
console.log("Step 4:", data);
if (data === 1) {
throw new Error("Fallback value");
} else {
return data * 3;
}
})
.catch(error => {
console.log("Step 5:", error.message);
return "Error handled";
})
.finally(() => {
console.log("Step 6: Finally block executed");
})

What will be the output of the above program?

  1. A

    Step 1: 0.6
    Step 2: 1.2
    Step 4: 6.2
    Step 6: Finally block executed

  2. B

    Step 1: 0.6
    Step 3: Less than 0.75
    Step 4: 1
    Step 5: Fallback value
    Step 6: Finally block executed

  3. C

    Step 1: 0.6
    Step 2: 1.2
    Step 3: Error
    Step 4: 1
    Step 5: Fallback value
    Step 6: Finally block executed

  4. D

    Step 1: 0.6
    Step 3: Less than 0.75
    Step 4: 1
    Step 6: Finally block executed

Show answer

Correct answer

  • B

    Step 1: 0.6
    Step 3: Less than 0.75
    Step 4: 1
    Step 5: Fallback value
    Step 6: Finally block executed

Question 26

+4.5 marksOne correct option

In a Vue CLI project with Vuex, you have the following configuration:

src/store/index.js:

javascript
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
value: " ",
},
mutations: {
setValue(state, payload) {
state.value = payload;
}
},
actions: {
async fetchValue({ commit }) {
// Simulate async API call
const response = await new Promise(resolve => setTimeout(() =>
resolve('API Value'), 500));
commit('setValue', response);
}
}
});

src/App.vue:

html
<template>
<div>
<p>{{ value }}</p>
<button @click="updateValue">Update Value</button>
</div>
</template>
<script>
export default {
computed: {
value() {
return this.$store.state.value;
}
},
methods: {
async updateValue() {
await this.$store.dispatch('fetchValue');
}
}
}
</script>

After running “npm run serve”, if you click the "Update Value" button, what will be displayed in the <p> tag?

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

Correct answer

  • A

Question 27

+4.5 marksOne correct option

Consider the below JavaScript code.

javascript
async function newFetch(url) {
try {
console.log(url)
const res = await fetch(url)
if (!res.ok) {
throw new Error(`HTTP Error: ${res.status}`)
}
try {
const data = await res.json()
console.log(data)
} catch {
throw new Error('Error')
}
} catch {
throw new Error('Data is not JSON serializable')
}
}
newFetch('https://example.com/api/users/23').catch((err) => {
console.error(err)
})

Suppose the API URL “https://example.com/api/users/23” returns a valid HTML output. What will be logged on to console?

  1. A

    “Network Error”

  2. B

    “HTTP Error: 404”

  3. C

    “Data is not JSON serializable”

  4. D

    Data returned by the API

Show answer

Correct answer

  • C

    “Data is not JSON serializable”

Question 28

+4.5 marksOne correct option

Consider the following Flask application with Redis caching. Redis is running normally on port 6379.

python
from flask import Flask, jsonify
from flask_caching import Cache
app = Flask(__name__)
app.config['CACHE_TYPE'] = 'redis'
app.config['CACHE_REDIS_HOST'] = 'localhost'
app.config['CACHE_REDIS_PORT'] = 6379
cache = Cache(app)
def compute_value(x, y):
result = x * y
return result
@app.route('/compute/<int:x>/<int:y>')
@cache.cached(timeout=60, key_prefix='compute')
def compute(x,y):
result = compute_value(x, y)
return jsonify({'result': result})
if __name__ == '__main__':
app.run(debug=True, port=5000)

Two requests are given to localhost:5000/compute/10/20 and localhost:5000/compute/5/10 within 60 seconds. What would be the json response from the server respectively?

  1. A

    {“result” : 200} and {“result”: 50}

  2. B

    {“result” : 50} and {“result”: 200}

  3. C

    {“result”: 100} and {“result” : 100}

  4. D

    {“result”: 200} and {“result”: 200}

Show answer

Correct answer

  • D

    {“result”: 200} and {“result”: 200}

Question 29

+3 marksOne correct option

Options:

A.

python
import requests
response = requests.get('https://some-api')
print(response.json())

B.

python
from flask import Flask, request
app = Flask(__name__)
@app.route('/server-route, methods=['POST'])
def server_route():
data = request.json
print(data)
return 'OK', 200

C.

python
from flask import Flask, Response
import time
app = Flask(__name__)
def stream():
while True:
time.sleep(5)
yield f'data: The time is {time.strftime("%Y-%m-%d %H:%M:%S")}\n\n'
@app.route('/server-route')
def server_route():
return Response(stream(), mimetype='text/event-stream')
if __name__ == '__main__':
app.run(debug=True, port=5000)

D.

python
import time
import requests
while True:
response = requests.get('https://some-endpoint')
print(response.json())
time.sleep(10)

Based on the above data, answer the given subquestions.

Which code snippet represents a Webhook receiver implementation?

  1. A

    A

  2. B

    B

  3. C

    C

  4. D

    D

Show answer

Correct answer

  • B

    B

Question 30

+2 marksOne correct option

Options:

A.

python
import requests
response = requests.get('https://some-api')
print(response.json())

B.

python
from flask import Flask, request
app = Flask(__name__)
@app.route('/server-route, methods=['POST'])
def server_route():
data = request.json
print(data)
return 'OK', 200

C.

python
from flask import Flask, Response
import time
app = Flask(__name__)
def stream():
while True:
time.sleep(5)
yield f'data: The time is {time.strftime("%Y-%m-%d %H:%M:%S")}\n\n'
@app.route('/server-route')
def server_route():
return Response(stream(), mimetype='text/event-stream')
if __name__ == '__main__':
app.run(debug=True, port=5000)

D.

python
import time
import requests
while True:
response = requests.get('https://some-endpoint')
print(response.json())
time.sleep(10)

Based on the above data, answer the given subquestions.

Which code snippet represents a Pub/Sub implementation?

  1. A

    A

  2. B

    B

  3. C

    C

  4. D

    D

Show answer

Correct answer

  • C

    C

Question 31

+3 marksOne correct option

Filename: script.js

javascript
const Error = {template: `<div>Page Not Found</div>`}
const Profile = {
template: `<div>
<div v-if='user'>
Name: {{user.name}}, State: {{user.state}}
</div>
<div v-else>
Unknown User
</div>
</div>`,
data() {
return {
profiles: [
{ id: '1234', name: 'Animesh', state: 'MP' },
{ id: '1235', name: 'Arnav', state: 'Goa' },
],
}
},
computed: {
user(){
let user = this.profiles.find((profile) => {
return profile.id == this.$route.params.id
})
return user
},
javascript
computed: {
user(){
let user = this.profiles.find((profile) => {
return profile.id == this.$route.params.id
})
return user
},
},
}
const routes = [
{ path: '/profile/:id', component: Profile },
{ path: '*', component: Error },
]
const router = new VueRouter({
routes,
})
new Vue({
el: '#app',
router,
})
  1. A

    Page Not Found

  2. B

    Unknown User

  3. C

    Name: Animesh, State: MP

  4. D

    Name: Arnav, State: Goa

Show answer

Correct answer

  • D

    Name: Arnav, State: Goa

Question 32

+2 marksOne correct option

Filename: script.js

javascript
const Error = {template: `<div>Page Not Found</div>`}
const Profile = {
template: `<div>
<div v-if='user'>
Name: {{user.name}}, State: {{user.state}}
</div>
<div v-else>
Unknown User
</div>
</div>`,
data() {
return {
profiles: [
{ id: '1234', name: 'Animesh', state: 'MP' },
{ id: '1235', name: 'Arnav', state: 'Goa' },
],
}
},
computed: {
user(){
let user = this.profiles.find((profile) => {
return profile.id == this.$route.params.id
})
return user
},
javascript
computed: {
user(){
let user = this.profiles.find((profile) => {
return profile.id == this.$route.params.id
})
return user
},
},
}
const routes = [
{ path: '/profile/:id', component: Profile },
{ path: '*', component: Error },
]
const router = new VueRouter({
routes,
})
new Vue({
el: '#app',
router,
})
  1. A

    Page Not Found

  2. B

    Name: Animesh, State: MP

  3. C

    Name: Arnav, State: Goa

  4. D

    Unknown User

Show answer

Correct answer

  • D

    Unknown User