Quiz Space

January 2024 term · Modern Application Development II · BSCS2006

MAD 2 End Term: 28 April 2024 (January 2024 term)

The IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 28 Apr 2024, in the January 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
25
MSQ
7

Updated

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

Question 1

+2 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
let langName = 'Python';
function showLanguage() {
let langName = "JavaScript";
let message = 'Learn ' + langName;
console.log(message);
}
let message = 'Learn ' + langName;
console.log(message)
console.log(showLanguage());

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • D

Question 2

+2 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
let x = [1, 'p', a => a + 1];
for (const i = 0; i<x.length; i++) {
console.log(i, x[i], typeof(x[i]))
}

Which of the following statement is correct, if the HTML document is rendered using a browser?

  1. A

    It will throw error on the console for the very first iteration.

  2. B

    It will display the index, value and type of the value for the first item of array and then will throw error for the next value.

  3. C

    It will display the indices, values and types of all the items of the array.

  4. D

    None of these.

Show answer

Correct answer

  • B

    It will display the index, value and type of the value for the first item of array and then will throw error for the next value.

Question 3

+2 marksOne correct option

Assuming the URL gives a valid json response, what will be the output in the console?

javascript
fetch('https://study.iitm.ac.in/api/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error(error));
console.log('End of script');
  1. A

    The JSON data from the specified URL followed by “End of script”.

  2. B

    "End of script" will be logged first, followed by the JSON data.

  3. C

    An error will be logged, and the script will terminate.

  4. D

    "End of script" will be logged, but the JSON data retrieval will fail.

Show answer

Correct answer

  • B

    "End of script" will be logged first, followed by the JSON data.

Question 4

+2 marksOne correct option

Which of the following statements is false regarding JavaScript and its behavior?

  1. A

    The language supports both first class and higher order functions.

  2. B

    The language supports higher order functions, but not first class functions.

  3. C

    A variable declared without keywords “var”, “let” or “const” is not hoisted at all.

  4. D

    The variables declared using keywords “let” and “const” are also hoisted.

Show answer

Correct answer

  • B

    The language supports higher order functions, but not first class functions.

Question 5

+2 marksOne correct option

Where is system state commonly stored in a web application?

  1. A

    Client Side local storage

  2. B

    In Memory Cache

  3. C

    Session Cookies

  4. D

    Server Side Database

Show answer

Correct answer

  • D

    Server Side Database

Question 6

+2 marksOne correct option

Which technology is commonly used to manage application state in a Vue.js application?

  1. A

    Vue.js

  2. B

    React.js

  3. C

    Vuex

  4. D

    Redux

  5. E

    Express.js

  6. F

    Angular

Show answer

Correct answer

  • C

    Vuex

Question 7

+3 marksOne or more correct options

Consider the following Script embedded in an HTML document.

javascript
let myQual = {
degree: "B-tech",
college: "IIT Delhi",
get qualification(){
return `degree: ${this.degree}, college: ${this.college}`
},
set qualification(q){
let components = q.split(' ');
this.degree = components[0];
this.college = components[1];
}
}

Which of the following statements will throw an error on the console when the HTML document is rendered using a browser?

Select all that apply.

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

Correct answers

  • A
  • D

Question 8

+3 marksOne or more correct options

Consider the following two HTML documents and the Vue app created in script.js file and select the correct option(s).

index1.html

html
<body>
<div id="app">
<h1 v-if="result">Hello am I visible?</h1>
</div>
<script src="./script.js"></script>
</body>

index2.html

html
<body>
<div id="app">
<h1 v-show="final">Hello am I visible?</h1>
</div>
<script src="./script.js"></script>
</body>

script.js

javascript
var app = new Vue({
el: '#app',
data: {
result: false,
final: false
}
})

Select all that apply.

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

Correct answers

  • B
  • D

Question 9

+3 marksOne or more correct options

Consider the following Vue application and the rendered HTML output below.

Filename: script.js

javascript
var app = new Vue({
el: '#app',
data: {
items:[
{id: 1, name:"mad 1"},
{id: 2, name:"mad 2"},
{id: 3, name:"mad 3"}
]
}
})

Rendered output:

mad 1

mad 2

mad 3

What should be the content of <div id = “app”></div> in index.html that generates the given rendered output?

Select all that apply.

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

Correct answers

  • A
  • C

Question 10

+3 marksOne or more correct options

Which of the following HTTP status code(s) is/are commonly used in RESTful APIs for successful responses?

Select all that apply.

  1. A

    200

  2. B

    201

  3. C

    400

  4. D

    404

  5. E

    500

Show answer

Correct answers

  • A

    200

  • B

    201

Question 11

+3 marksOne or more correct options

Which of the following is/are potential benefit(s) of using caching in web applications?

Select all that apply.

  1. A

    Reduced latency and faster response times

  2. B

    Lower server load and reduced bandwidth usage

  3. C

    Improved scalability and better handling of traffic spikes

  4. D

    Enhanced security and protection against DDoS attacks

Show answer

Correct answers

  • A

    Reduced latency and faster response times

  • B

    Lower server load and reduced bandwidth usage

  • C

    Improved scalability and better handling of traffic spikes

Question 12

+3 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
class Twowheeler {
constructor(name){
this.name = name;
this.gear = 4;
this.seating = 2;
}
get description(){
return `${this.name} has ${this.gear} gear and has
${this.engine} engine.`
}
}
class Moped extends Twowheeler {
constructor(name){
super(name);
this.engine = '4 stroke'
}
}
let myBike = new Twowheeler("Discover")
let myDrive = new Moped("Activa")
console.log(myDrive.description)
console.log(myBike.description)

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • C

Question 13

+3 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
function parentFunc(name) {
return {
sayHello: () => "Hi! " + name,
sayBye: () => "Bye! " + name,
changeName: (newName) => {
name = newName;
},
};
}
const arpan = parentFunc("Arpan");
const beli = parentFunc("Beli");
console.log(arpan.sayHello());
console.log(beli.sayHello());
arpan.changeName("Beli");
console.log(arpan.sayBye());

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • B

Question 14

+3 marksOne correct option

What will be the text displayed in a web page if the Vue app given below is running in a development mode?

Filename: index.html

html
<div id="app1">
<h1>{{ title }}</h1>
<h4>{{ greetings() }}</h4>
</div>
<div id="app2">
<h1>{{ title }}</h1>
<h4>{{ greetings }}</h4
</div>

Filename: app.js

javascript
new Vue({
el: "#app1",
data: { title: "App No 1" },
computed: {
greetings() {
return "hello from " + this.title;
},
},
});
new Vue({
el: "#app2",
data: { title: "App No 2" },
computed: {
greetings() {
return "hello from " + this.title;
},
},
});
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 15

+3 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
var var1 = 25;
var var2 = 35;
const myObj = {
var2: 45,
var1: 35,
ObjFunc: function(var3){
let var4 = var3**2;
return 10 + this.var2 + var4;
}
}
let m = myObj.ObjFunc
console.log(m.bind()(5))
console.log(m.call(myObj,6))

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • B

Question 16

+3 marksOne correct option

What does the “finally” method do in promises?

  1. A

    The method is executed when the promise is fulfilled.

  2. B

    The method is executed when the promise is rejected.

  3. C

    The method is executed regardless of whether the promise is fulfilled or rejected.

  4. D

    The method can not be used with promises at all.

Show answer

Correct answer

  • C

    The method is executed regardless of whether the promise is fulfilled or rejected.

Question 17

+3 marksOne correct option

Which of the following statements regarding Celery task execution is correct?

  1. A

    Celery tasks are executed synchronously by default.

  2. B

    Celery tasks can only be executed on the same machine where the flask application is running.

  3. C

    Celery tasks are executed asynchronously by default.

  4. D

    Celery tasks can only be executed once they are defined as part of a flask application.

Show answer

Correct answer

  • C

    Celery tasks are executed asynchronously by default.

Question 18

+3 marksOne correct option

What is the primary objective of using a message broker?

  1. A

    Eliminates the need for network communication

  2. B

    Decouples producers and consumers

  3. C

    Decreases CPU utilization

  4. D

    Reduces the need for data serialization

Show answer

Correct answer

  • B

    Decouples producers and consumers

Question 19

+3 marksOne correct option

In a message broker system, what does the term "topic" refer to?

  1. A

    The physical location where messages are stored.

  2. B

    A unique identifier for a message.

  3. C

    The process of encrypting messages.

  4. D

    A channel to which messages are published.

Show answer

Correct answer

  • D

    A channel to which messages are published.

Question 20

+3 marksOne correct option

What is the primary advantage of using server-sent events over traditional polling?

  1. A

    Server-sent events support bidirectional communication.

  2. B

    Server-sent events can handle larger payloads.

  3. C

    Server-sent events reduce server load by eliminating the need for frequent polling.

  4. D

    Server-sent events provide lower latency compared to polling.

Show answer

Correct answer

  • C

    Server-sent events reduce server load by eliminating the need for frequent polling.

Question 21

+3 marksOne correct option

Which of the following protocols is commonly used for implementing polling?

  1. A

    HTTP

  2. B

    Web Sockets

  3. C

    FTP

  4. D

    SMTP

Show answer

Correct answer

  • A

    HTTP

Question 22

+3 marksOne correct option

What is the primary purpose of CORS in web security?

  1. A

    To prevent unauthorized access to confidential data

  2. B

    To mitigate cross-site scripting (XSS) attacks

  3. C

    To enable controlled access to resources from different origins

  4. D

    To protect against SQL injection attacks

Show answer

Correct answer

  • C

    To enable controlled access to resources from different origins

Question 23

+4.5 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
let Obj1 = {
subject:'Mechanics',
stream:'Physics'
}
let Obj2 = Obj1;
let Obj3 = {};
for (let key in Obj1){
Obj3[key] = Obj1[key];
}
Obj2.subject = 'Thermodynamics'
Obj3.stream = 'Chemistry'
console.log(Obj1)

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • A

Question 24

+4.5 marksOne correct option

Consider the following Script embedded in an HTML document.

javascript
var var1 = 25;
const exObj = {
var2: 45,
var1: 35,
inObj : {
var1: 45,
inObjFunc: ()=>{
return "Value is " + this.var1;
}
},
exObjFunc: function(){
let var2 = 10;
return "Value is " + this.var2;
}
}
let x = exObj.inObj
console.log(x.inObjFunc())
console.log(exObj.exObjFunc())

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • D

Question 25

+4.5 marksOne correct option

Consider the following Script “script.js” embedded in an HTML document, “index.html” and an external script “app.js” given below.

Filename: index.html

html
<html lang="en">
<head></head>
<body>
<script src="./script.js"></script>
</body>
</html>

Filename: script.js

javascript
function loadScript(src, cbf){
let script = document.createElement('script');
script.src = src;
script.onload = () => cbf();
document.head.append(script);
}
let cbf = function(){
console.log("callback function executed here.");
extFunc()
}
loadScript("./support_m6.js", cbf)
extFunc()

Filename: app.js

javascript
console.log("Now I am loaded, let's support")
function extFunc(){
console.log("loaded and run from external script")
}

What will be the output on console, if the HTML document is rendered using a browser?

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

Correct answer

  • D

Question 26

+4.5 marksOne correct option

Consider the below JavaScript program.

javascript
Array.prototype.double = function (arr) {
const res = [];
for (let i=0; i<placeholder.length; i++)
res.push(placeholder[i] * 2);
return res;
}
const arr = [2, 3, 7, 8];
console.log(arr.double());

What of the following can be used in place of “placeholder” in the above program so that the program yields the below output array?

[ 4, 6, 14, 16 ]

  1. A

    arr

  2. B

    Array

  3. C

    this

  4. D

    The program cannot yield such an output, and is implemented in a wrong way.

Show answer

Correct answer

  • C

    this

Question 27

+4.5 marksOne correct option

Consider the below JavaScript program.

javascript
const fetchData = (url) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
if (url.includes("success")) {
resolve(`Data fetched successfully from: ${url}`);
} else {
reject(`Error fetching data: ${url}`);
}
}, 1000);
});
};
const processData = (data) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(`Processed data: ${data.toUpperCase()}`);
}, 500);
});
};
const handleError = (error) => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(`Handled Error: ${error}`);
}, 300);
});
};
fetchData("https://example.com/success")
.then(processData)
.then(fetchData)
.then(handleError)
.then((result) => {
console.log(result);
})
.catch((error) => {
console.error(error);
});

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

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

Correct answer

  • B

Question 28

+4.5 marksOne correct option

Consider the following Vuex module definition for managing a shopping cart.

javascript
const cartModule = {
state: {
items: []
},
mutations: {
addItem(state, item) {
state.items.push(item);
},
},
actions: {
async addToCart({ commit }, item) {
// TODO: Implement adding item to cart
},
},
}

Which of the following options correctly completes the code for the “addToCart” action function?

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

Correct answer

  • A

Question 29

+4.5 marksOne correct option

Consider the following Vue application with markup “index.html” and JavaScript file “app.js”.

index.html:

html
<div id = "app">
<input v-model = "subject" @input = "compute_marks">
<p> {{marks}} </p>
</div>
<script scr = "app.js"></script>

app.js:

javascript
new Vue({
el : "#app",
data : {
subject : "AppDev",
marks : 50,
},
mounted () {
this.subject = "AppDev";
this.marks = 50;
if (localStorage.marks) {
this.subject += "1";
this.marks = parseInt(localStorage.marks) + 20;
localStorage.marks = this.marks;
localStorage.subject = this.subject;
}
else {
this.subject += "2";
this.marks += 20;
}
},
methods : {
compute_marks() {
localStorage.setItem("subject", this.subject);
localStorage.setItem("marks", this.marks + 10);
}
}
})

Suppose you open “index.html” file in a browser, and type the text “EndTermExam” in the text box shown (after removing the previous text, if any), and hard refresh the page thrice, without clicking anywhere. What will be the value shown in the text box, and the “marks” placeholder, respectively?

  1. A

    AppDev1, 120

  2. B

    AppDev2, 120

  3. C

    AppDev1, 140

  4. D

    AppDev2, 140

Show answer

Correct answer

  • C

    AppDev1, 140

Question 30

+4.5 marksOne correct option

Consider the following Vue application with markup “index.html” and JavaScript file “app.js”.

index.html:

html
<div id="app">
<router-link :to="{ name: 'user', params: { id: 'Jyoti' }}">User
Profile</router-link>
<router-view></router-view>
</div>
<script src="app.js"></script>

app.js:

javascript
const UserProfile = {
template: `
<div>
<h1>User Profile</h1>
<p>User ID: {{ id }}</p>
</div>
`,
props: ['id']
};
const routes = [
{ path: '/user/:id', name: 'user', component: UserProfile, props: true }
];
const router = new VueRouter({
routes
});
new Vue({
el: '#app',
router,
});

Based on this setup, what will be displayed in the browser when the user clicks on the "User Profile" link?

  1. A

    An error indicating that the id prop is not defined.

  2. B

    User Profile
    User ID: Jyoti

  3. C

    An error indicating that the data object is not defined.

  4. D

    An error indicating that the route does not exist.

  5. E

    User Profile
    User ID:

Show answer

Correct answer

  • B

    User Profile
    User ID: Jyoti

Question 31

+2 marksOne or more correct options

Which of the following is/are built in Vue.js lifecycle hook(s)?

Select all that apply.

  1. A

    beforeLoad

  2. B

    preUpdate

  3. C

    mounted

  4. D

    updated

Show answer

Correct answers

  • C

    mounted

  • D

    updated

Question 32

+2 marksOne or more correct options

Which of the following JavaScript method(s) is/are used to remove data from the session storage?

Select all that apply.

  1. A

    clear()

  2. B

    removeItem()

  3. C

    deleteItem()

  4. D

    unSet()

Show answer

Correct answers

  • A

    clear()

  • B

    removeItem()