uiz Space

January 2024 term · Modern Application Development II · BSCS2006

Modern Application Development II Quiz 2: 24 March 2024 (January 2024 term)

The IIT Madras BS Modern Application Development II (MAD 2) Quiz 2 paper sat on 24 Mar 2024, in the January 2024 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
8
MSQ
8

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 24 Mar 2024 · No negative marking.

Question 1

+3 marksOne correct option

Consider the below javascript program.

javascript
var first = 30
const obj1 = {
first: 50,
second: () => {
console.log("Value:", this.first);
}
}
const obj2 = {
first: 80,
second: function () {
console.log("Value:", this.first);
this.second();
}
}
obj2.second.call(obj1);

What will be the output of the program, if executed in a REPL environment?

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

Correct answer

  • D

Question 2

+3 marksOne correct option

Consider the below JavaScript code.

javascript
function isValidAge(age) {
return !(age > 18)
}
const validAgeParams = {
voter_id: 123,
constituency: 'New Delhi'
}
const teenageParams = {
age_criteria: '<18',
}
let some_value;
console.log(
isValidAge(some_value) ? {
'name': 'ABC',
...(!isValidAge(19) && validAgeParams)
} : {
'name': 'XYZ',
...(isValidAge(19) && teenageParams)
}
);

What will be the output of the above program, assuming the value of the variable “some_value” is less than 18?

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

Correct answer

  • B

Question 3

+3 marksOne correct option

Consider the below JavaScript program.

javascript
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('First promise resolved');
}, 1000);
});
promise1
.then((result) => {
console.log(result);
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Second promise resolved');
}, 3000);
});
})
.then((result) => {
console.log(result);
return new Promise((resolve, reject) => {
setTimeout(() => {
reject('Third promise resolved');
}, 3000);
});
})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.log("Promise chain interrupted. Reason:", 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

  • C

Question 4

+3 marksOne correct option

Consider the following Script embedded in an HTML document.

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 5

+3 marksOne correct option

Fill in property_name & definition, which can be used in Vuex Store to update the “best_food” state variable with the objects of those food items which have their calorific value less than 300.

javascript
const store = new Vuex.Store({
state:{
foods:[
{"name":"Sandwich", "calories":100},
{"name":"Pizza", "calories": 1250},
{"name":"Chips", "calories": 700}
],
best_food: []
},
=property_name=:{
get_best_food: function(state) {
=========== definition ============
}
},
})
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 6

+2 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
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 7

+4.5 marksOne correct option

Consider the below JavaScript program.

javascript
const promise1 = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('First promise resolved');
}, 1000);
});
promise1
.then((result) => {
console.log(result);
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Second promise resolved');
}, 3000);
});
})
.then((result) => {
console.log(result);
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Third promise resolved');
}, 3000);
});
})
.then((result) => {
console.log(result);
})
.catch((error) => {
console.log("Promise chain interrupted. Reason:", error);
});

Considering the asynchronous nature of promises in the above JavaScript program, what is the minimum time (in seconds) it will take for the entire execution to complete?

  1. A

    The program will never end

  2. B

    0 second

  3. C

    1 second

  4. D

    7 seconds

  5. E

    9 seconds

Show answer

Correct answer

  • D

    7 seconds

Question 8

+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 = "course" @input = "do_something">
<p> {{role}} </p>
</div>

app.js:

javascript
new Vue({
el : "#app",
data : {
course : "#app",
role : "user",
},
mounted () {
try {
this.course = localStorage.getItem("course").split(" ")[0];
this.role = localStorage.getItem("course").split(" ")[1];
localStorage.setItem("course",
localStorage.getItem("course").split(" ")[0] + " " +
this.course);
}
catch {
this.course = "MAD_II";
this.role = "admin";
}
},
methods : {
do_something() {
localStorage.setItem("course", this.course);
localStorage.setItem("role", this.role);
}
}
})

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

  1. A

    MAD_II, admin

  2. B

    App, Dev

  3. C

    App, App

  4. D

    Dev, App

Show answer

Correct answer

  • C

    App, App

Question 9

+2 marksOne or more correct options

Which of the following statement(s) is/are correct regarding web storage APIs?

Select all that apply.

  1. A

    Web Storage APIs provide a way to store key-value pairs persistently on the client side.

  2. B

    Web Storage APIs include “localStorage” and “sessionStorage”.

  3. C

    Data stored in “localStorage” is automatically cleared when the browser session ends.

  4. D

    The “sessionStorage” allows data to persist across browser sessions.

Show answer

Correct answers

  • A

    Web Storage APIs provide a way to store key-value pairs persistently on the client side.

  • B

    Web Storage APIs include “localStorage” and “sessionStorage”.

Question 10

+2 marksOne or more correct options

Which of the following is a valid function signature for an action function in Vuex?

Select all that apply.

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

Correct answers

  • A
  • B

Question 11

+2 marksOne or more correct options

Select the statements that incorrectly describe characteristics or practices related to RESTful APIs.

Select all that apply.

  1. A

    Stateless communication

  2. B

    Use of SOAP for data exchange

  3. C

    Emphasis on nouns (resources) in URIs

  4. D

    Strict requirement for XML as the data format

  5. E

    Utilization of standard HTTP methods

Show answer

Correct answers

  • B

    Use of SOAP for data exchange

  • D

    Strict requirement for XML as the data format

Question 12

+3 marksOne or more correct options

Which of the following statement(s) is/are true regarding Single Page Applications (SPA) and Progressive Web Apps (PWA)?

Select all that apply.

  1. A

    SPAs load entire web pages from the server for each user interaction.

  2. B

    PWAs can be installed on a user's device and accessed from the home screen.

  3. C

    SPAs often rely on client-side routing to update the content dynamically.

  4. D

    PWAs always require an internet connection to function.

  5. E

    SPAs may result in faster user experiences as they avoid full-page reloads.

  6. F

    PWAs use service workers to enable offline capabilities.

Show answer

Correct answers

  • B

    PWAs can be installed on a user's device and accessed from the home screen.

  • C

    SPAs often rely on client-side routing to update the content dynamically.

  • E

    SPAs may result in faster user experiences as they avoid full-page reloads.

  • F

    PWAs use service workers to enable offline capabilities.

Question 13

+3 marksOne or more correct options

Identify the correct statement(s) about the behavior of promise chains in JavaScript.

Select all that apply.

  1. A

    A "finally" block always comes at the end of the promise chain.

  2. B

    Every "catch" block must always be preceded by a "then" block.

  3. C

    A promise chain may consist of a number of "then" blocks.

  4. D

    The "finally" block always gets executed, irrespective of the promise outcome.

Show answer

Correct answers

  • C

    A promise chain may consist of a number of "then" blocks.

  • D

    The "finally" block always gets executed, irrespective of the promise outcome.

Question 14

+3 marksOne or more correct options

Consider the below Vue class binding.

Script.js:

javascript
var app = new Vue({
el: '#app',
data : {
classObj : {
is_active: true,
completed: false
},
myClass: 'is_active',
status: true
}
})

Code 1:

html
<div :class="classObj"></div>

Code 2:

html
<div :class="[status ? myClass : '']"></div>

Which of the following statements is/are true, assuming both code 1 and code 2 are part of app object?

Select all that apply.

  1. A

    The code snippet 1 will render the div element with class “completed”, if the “completed” property of “classObj” is set to true.

  2. B

    The code snippet 2 will render the div element with class “completed”, if the data variable “status” is set to true.

  3. C

    Both the code snippets will render same HTML

  4. D

    Both the code snippets will render different HTML

Show answer

Correct answers

  • A

    The code snippet 1 will render the div element with class “completed”, if the “completed” property of “classObj” is set to true.

  • C

    Both the code snippets will render same HTML

Question 15

+4.5 marksOne or more correct options

Consider the below Vue component template and script definitions that use Vue router.

Template:

html
<template>
<div>
<h1>{{ pageTitle }}</h1>
<router-link to="/home" v-if="showHomeLink">Home</router-link>
<router-link to="/about" v-if="showAboutLink">About</router-link>
<router-view></router-view>
</div>
</template>

Script:

html
<script>
export default {
name: 'App',
data() {
return {
pageTitle: 'Vue Router Demo',
showHomeLink: true,
showAboutLink: false,
};
},
watch: {
'$route.path'() {
if (this.$route.path === '/home') {
this.showAboutLink = true;
this.showHomeLink = false;
this.pageTitle = 'Home Page';
} else if (this.$route.path === '/about') {
this.showAboutLink = false;
this.showHomeLink = true;
this.pageTitle = 'About Page';
} else {
this.pageTitle = 'Vue Router Demo';
}
},
},
};
</script>

Assuming that the corresponding routes are properly configured, what does this component structure accomplish?

Select all that apply.

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

Correct answers

  • B
  • D

Question 16

+4.5 marksOne or more correct options

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

Filename: index.html

html
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js"></script>
</body>

Filename: app.js

javascript
const records = {
1: {albums: "Heartrisers", songs: 20, genre: 4},
2: {albums: "Pianobind", songs: 13, genre: 5}
}
const notFound = { template: `<h1>Unknown record!</h1>` }
const myRecords = {
template: `<h1>{{record.albums}} has {{record.songs}} songs across
{{record.genre}} genres.</h1>`,
data() {
return {record: records[this.$route.params.id]}
},
}
const router = new VueRouter({
routes: [
{ path: '/records/:id', component: myRecords },
{ path: '*', component: notFound },
],
})
new Vue({
el: '#app',
template: '<div><router-view /></div>',
router,
})

Suppose the application is running on “http://127.0.0.1:8080”, select the correct option(s)?

Select all that apply.

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

Correct answers

  • B
  • C