Home / Past papers / MAD2 End Term / this paper

THIS IS QUESTION PAPER FOR THE SUBJECT "DIPLOMA LEVEL: MODERN APPLICATION DEVELOPMENT 2" ARE YOU SURE YOU HAVE TO WRITE EXAM FOR THIS SUBJECT? CROSS CHECK YOUR HALL TICKET TO CONFIRM THE SUBJECTS TO BE WRITTEN. (IF IT IS NOT THE CORRECT SUBJECT, PLS CHECK THE SECTION AT THE TOP FOR THE SUBJECTS REGISTERED BY YOU)
Which of the following shows the correct output if the javascript program written below is executed? ```javascript const arr = [1, 2, 3, 4, 5, 6, 7, 8] const arr1 = arr.map(r => r**3) const arr2 = arr1.filter(r => ((r % 3 == 2) || (r % 4 == 3))) console.log(arr2) ```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose you open “index.html” file in a browser, and type the text “IIT Madras” 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?index.html:
```html
<div id = "app">
<input v-model = "name" @input = "do_something">
<p>{{age}}</p>
</div>
<script scr = "app.js"></script>
```
app.js:
```javascript
new Vue({
el : "#app",
data : {
name : "#app",
age : 0,
},
mounted () {
try {
this.name = localStorage.getItem("name").split(" ")[0];
this.age = localStorage.getItem("name").split(" ")[1];
}
catch {
this.name = "Default";
this.age = "Default";
}
},
methods : {
do_something() {
localStorage.setItem("name", this.name);
localStorage.setItem("age", this.age);
}
}
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be the color of text rendered inside the div with ID “run”, if the user clicks on the button with text “Six”, 3 times and the button with text “Four”, 4 times?index.html:
```html
<html>
<head>
<style>
.onstrike {
color: blue;
}
</style>
</head>
<body>
<div id="app">
<div :class="{onstrike:changeStrike}" id="run">{{ run }}</div>
<button @click="run+=4">Six</button>
<button @click="run+=3">Four</button>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
</html>
```
app.js:
```javascript
new Vue({
el: '#app',
data: { run: 0 },
computed: {
changeStrike() {
return this.run % 2 === 0 ? true : false
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be the color and font-weight of the text “IITM online degree”?index.html:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.active {
color: blue;
}
.bold {
font-weight: bold;
}
</style>
</head>
<body>
<div id="app">
<Home class="bold" />
</div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</html>
```
app.js:
```javascript
Vue.component('Home', {
template: `<div class='active'>
IITM online degree
</div>`,
})
new Vue({
el: '#app',
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered on the screen?index.html:
```html
<body>
<div id="app">
<template v-for="cont in contributions">
<div>{{cont.player}}: {{cont.run}}/{{partnerShip}}</div>
</template>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
new Vue({
el: '#app',
data: {
partnerShip: 210,
contributions: [
{ player: 'Rohit', run: 100 },
{ player: 'Kohli', run: 110 },
],
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div with ID “collections”, when the user selects the option “Type Two” ?```html
index.html:
<body>
<div id="app">
<div>
<select v-model="collType">
<option value="all">All</option>
<option value="typeOne">Type One</option>
<option value="typeTwo">Type Two</option>
</select>
</div>
<div id="collections">
<Numbers :numbers="numbers" v-show="collType==='all' "
/></Numbers>
<Numbers :numbers="typeOne" v-show="collType==='typeOne' "
/></Numbers>
<Numbers :numbers="typeTwo" v-show="collType==='typeTwo' "
/></Numbers>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('Numbers', {
template: `<div>
<span v-for="num in numbers">
{{num}}
</span></div>`,
props: ['numbers'],
})
new Vue({
el: '#app',
data: {
numbers: [2, 3, 4, 6, 7],
collType: 'typeOne',
},
computed: {
typeOne() {
return this.numbers.filter((num) => num % 2 === 0)
},
typeTwo() {
return this.numbers.filter((num) => num % 2 !== 0)
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the user types “Apple” in the input box (after removing the existing text, if any). What will be rendered inside the div with ID “result”?index.html:
```html
<body>
<div id="app">
<custom-input v-model="searchText"></custom-input>
<div id="result">Searching for: {{searchText}}</div>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('custom-input', {
props: ['value'],
template: `
<input
v-bind:value="value"
v-on:input="$emit('input', $event.target.value)"
>
`
})
new Vue({
el: '#app',
data: { searchText: 'type something ...' },
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the application is running on ‘http://127.0.0.1:8080/’. If the user visits the application for the first time and clicks on the button “Go to profile”, what will be displayed on the screen?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const Profile = {
template: `<div> Welcome {{this.$route.params.name}}</div>`,
}
const Home = {
template: `<div> This is home page
<button @click='goToProfile'> Go to profile </button>
</div>`,
methods: {
goToProfile() {
this.$router.push({ name: 'profile', params: { name: 'narendra' } })
}
},
}
const router = new VueRouter({
routes: [
{ path: '/profile/:name', name: 'profile', component: Profile },
{ path: '/', component: Home },
],
})
new Vue({
el: '#app',
router,
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose the application is running on ‘http://127.0.0.1:8080/’. What will be rendered for the URL “http://127.0.0.1:8080/#/” ?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
```javascript
app.js:
const Movies = {
template: `<div><ul>
<div>Movies</div>
<router-view />
</ul></div>`,
}
const Error = {
template: `<div> Some Error</div>`,
}
const Hindi = {
template: `<div><ul>
<li v-for='movie in hindiMovies'>{{movie.name}}</li>
</ul></div>`,
data() {
return {
movies: [
{ name: 'Soley', language: 'hindi' },
{ name: 'Dexter', language: 'english' },
],
}
},
computed: {
hindiMovies() {
return this.movies.filter((movie) => {
return movie.language === 'english'
})
},
},
}
const router = new VueRouter({
routes: [
{
path: '/',
component: Movies,
children: [
{ path: 'hindi', component: Hindi },
{ path: '*', component: Error },
],
},
],
})
new Vue({
el: '#app',
router,
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the “custom-comp” component?index.html:
```html
<body>
<div id="app">
<custom-comp ref="custom" />
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('custom-comp', {
data() {
return { name: 'Rohit Sharma' }
},
template: `<div>Welcome {{name}}</div>`,
})
new Vue({
el: '#app',
mounted() {
this.$refs.custom.name = 'Virat Kohli'
},
})
```
Which of the following is the correct way to do class binding in Vue (to apply ‘classA’ on the div element), if the data object in the Vue constructor is defined as below? ```
data : {
classObj : {
classA : true,
classB : false
},
classA : true,
classB : false,
}
```
```html
<div :class="{classA : classA, classB : classB}"></div>
```
```html
<div :class="{classA : 'classA', classB : 'classB'}"></div>
```
```html <div :class = "classObj"></div> ```

```html
<div :class="{classObj}"></div>
```
Which of the following shows the correct output, if the javascript program written below is executed? ```javascript
new Promise((reject, resolve) => {
let a = 2 * 4 || 0 / 4;
let b = 3 * 4 && 0 / 4;
if (a > b) resolve(a);
else reject(b);
})
.then((d) => console.log("Passed:", d))
.catch((e) => console.log("Failed:", e))
.finally((d) => {
console.log("About to finish");
return "Over";
})
.then((d) => console.log("Finished !!", d));
```

Suppose you own a company where you want to hire candidates for an upcoming project on a deputation basis, and you have received a lot of applications. On discussing with your team members, you decided to shortlist the candidates based on the following 2 criteria:
1. The candidate must have at least 3 years of experience
2. The candidate's age must be less than 30 years
Fill in the `code1` & `code2`, which can be used in Vuex Store to update the "shortlisted" state variable with the objects of those candidates who satisfy the above-mentioned criteria. Also, predict the length of the state variable "shortlisted", after the mutation has completed its execution.
```javascript
const store = new Vuex.Store({
state : {
candidates : [
{
name : 'sample1',
age : 28,
experience : 2.5
},
{
name : 'sample2',
age : 35,
experience : 3.5
},
{
name : 'sample3',
age : 32,
experience : 3
},
{
name : 'sample4',
age : 38,
experience : 2
},
],
shortlisted : []
},
mutations : {
update_final(state, minimum) {
for (candidate of state.candidates)
code2
},
},
actions : {
send_task : function (context) {
code1
}
}
})
```
```
code1: this.$store.commit("update_final", 2);
code2: if (candidate.experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
Length: 3
```
```
code1: context.commit("update_final", 2);
code2: if (experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 2
```javascript
code1: this.$store.commit("update_final", 3);
code2: if (experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 3
```
code1: context.commit("update_final", 3);
code2: if (candidate.experience >= minimum && candidate.age < 30)
state.shortlisted.push(company)
```
Length: 2
Consider the following javascript program, and predict the output, if executed. ```javascript
let propA = 10;
const obj1 = {
propA : 20,
propB : function () {
console.log(propA, this.propA)
}
}
const obj2 = {
propA : 30,
propB : function () {
let func = () => console.log(propA, this.propA)
func()
}
}
obj2.propB.call(obj1);
```
Consider the following javascript program, and predict the output, if executed. Also, predict the minimum time taken (in seconds) to log the value “Executing” on the console. ```javascript
async function some () {
let promise = await new Promise((res, rej) => {
setTimeout(() => res("Execution Started"), 1000)
});;
let a = await promise;
let b = a.replace("e", "")
return new Promise ((rej, res) => {
let c = a + "\n" + b;
rej(c);
})
}
some().then(d => console.log(d)
).catch(e => console.log("Error"))
console.log("Executing")
```
Consider the following JavaScript program. What will be logged on to the console?```javascript
const p = function (t) {
return new Promise(((resolve, reject) => {
setTimeout((() => {
resolve(t)
}), t * 1000)
}))
}
data = []
asyncFunc = async function () {
p1 = await p(1)
p2 = await p(2)
data.push(p2)
data.push(p1)
}
asyncFunc()
data.push('Outer')
console.log(data)
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div for ID “run”, if the user clicks on the button with text “Six”, 3 times and the button with text “Four”, 4 times?index.html:
```html
<html>
<head>
<style>
.onstrike {
color: blue;
}
</style>
</head>
<body>
<div id="app">
<div :class="{onstrike: changeStrike}" id="run">{{run}}</div>
<button @click="run+=4">Six</button>
<button @click="run+=3">Four</button>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
</html>
```
app.js:
```javascript
new Vue({
el: '#app',
data: { run: 0 },
computed: {
changeStrike() {
return this.run % 2 === 0 ? true : false
},
},
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the div with ID “collections”, when the browser loads the application for the first time?index.html:
```html
<body>
<div id="app">
<div>
<select v-model="collType">
<option value="all">All</option>
<option value="typeOne">Type One</option>
<option value="typeTwo">Type Two</option>
</select>
</div>
<div id="collections">
<Numbers :numbers="numbers" v-show="collType==='all'"></Numbers>
<Numbers :numbers="typeOne" v-show="collType==='typeOne'"></Numbers>
<Numbers :numbers="typeTwo" v-show="collType==='typeTwo'"></Numbers>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
Vue.component('Numbers', {
template: `<div>
<span v-for="num in numbers">
{{num}}
</span></div>`,
props: ['numbers'],
})
new Vue({
el: '#app',
data: {
numbers: [2, 3, 4, 6, 7],
collType: 'typeOne',
},
computed: {
typeOne() {
return this.numbers.filter((num) => num % 2 === 0)
},
typeTwo() {
return this.numbers.filter((num) => num % 2 !== 0)
},
}
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”.
Consider the following Vue application with markup “index.html” and javascript file “app.js”. What will be rendered inside the router-view component of Movies component for the URL “http://127.0.0.1:8080/#/hindi”?index.html:
```html
<body>
<div id="app">
<router-view></router-view>
</div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"
></script>
<script
src="https://unpkg.com/vue-router@2.0.0/dist/vue-router.js"
></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const Movies = {
template: `<div><ul>
<div>Movies</div>
<router-view />
</ul></div>`,
}
const Error = {
template: `<div> Some Error</div>`,
}
const Hindi = {
template: `<div><ul>
<li v-for='movie in hindiMovies'>{{ movie.name }}</li>
</ul></div>`,
data() {
return {
movies: [
{ name: 'Soley', language: 'hindi' },
{ name: 'Dexter', language: 'english' },
],
}
},
computed: {
hindiMovies() {
return this.movies.filter((movie) => {
return movie.language === 'english'
})
},
},
}
const router = new VueRouter({
routes: [
{
path: '/',
component: Movies,
children: [
{ path: 'hindi', component: Hindi },
{ path: '*', component: Error },
],
},
],
})
new Vue({
el: '#app',
router,
})
```Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of the core topics, concepts, principles, and equations essential for the "Modern Application Development 2" exam, along with Mermaid knowledge graphs to visualize relationships.
Primitive Data Types
string, number, boolean, null, undefined, symbol (and bigint in ES2020).int or char (unlike Java/C++).Variable Scoping
const: Block-scoped, cannot be reassigned (but can be mutated if it’s an object/array).let: Block-scoped, can be reassigned.var: Function-scoped (avoid due to hoisting issues).First-Class & Higher-Order Functions
map, filter, reduce).Closures
Example:
function outer() {
let x = 10;
return function inner() { console.log(x); };
}
const closure = outer(); // Closure remembers `x`.
closure(); // Logs 10.Arrow Functions & this Binding
this; they inherit it from the parent scope.this dynamically (based on how they’re called).Promises & Async/Await
pending → fulfilled (resolved) or rejected.Methods:
.then(): Handles resolution..catch(): Handles rejection..finally(): Runs regardless of outcome.Async/Await: Syntactic sugar for promises.
await pauses execution until the promise settles.try/catch for error handling.Logical Operators (&&, ||)
|| (OR): Returns the first truthy value or the last falsy value.&& (AND): Returns the first falsy value or the last truthy value.Example:
let a = 2 * 4 || 0 / 4; // 8 (2*4 is truthy)
let b = 3 * 4 && 0 / 4; // 0 (0/4 is falsy)javascript new Promise((resolve, reject) => { if (condition) resolve(value); else reject(error); }) .then(d => console.log("Resolved:", d)) .catch(e => console.log("Rejected:", e)) .finally(() => console.log("Done")); ``javascript async function fetchData() { try { let data = await someAsyncTask(); console.log(data); } catch (err) { console.error(err); } } ``javascript function createCounter() { let count = 0; return function() { return ++count; }; } const counter = createCounter(); console.log(counter()); // 1 ``Authentication vs. Authorization
OAuth 2.0: Authorization framework (delegates access to resources).
Tokens & Cookies
Cookies:
JWT (JSON Web Tokens):
Authorization header.CSRF (Cross-Site Request Forgery):
{{ csrf_token() }}).CORS (Cross-Origin Resource Sharing):
Access-Control-Allow-Origin, Access-Control-Allow-Credentials.Credentials mode:
include: Send cookies in cross-origin requests.omit: Exclude cookies.same-origin: Default (send only for same origin).API Design Best Practices
RESTful APIs:
/users, not /getUsers).GET, POST, PUT, DELETE).JAMStack:
Server-Sent Events (SSE)
EventSource API.javascript fetch('https://api.example.com/data', { credentials: 'include' // Send cookies }); ``http Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true ``javascript // Server sends POST to client's webhook URL on event (e.g., push). app.post('/webhook', (req, res) => { const payload = req.body; // e.g., GitHub push event // Process payload... }); ``Celery & Redis
Celery: Distributed task queue for Python.
Components:
Task Dispatching:
task.delay(): Immediate execution.task.apply_async(countdown=10): Delayed execution (10 seconds).Message Brokers vs. Point-to-Point
Message Broker (e.g., Redis, RabbitMQ):
Point-to-Point:
@app.task def send_email(): # Task logic pass
# Dispatch immediately send_email.delay()
# Dispatch after 10 seconds send_email.apply_async(countdown=10) ```
Vue.js Fundamentals
Directives:
v-model: Two-way data binding.v-for: Render lists.v-if/v-show: Conditional rendering.v-bind: Bind attributes (e.g., :class).v-on: Event handling (e.g., @click).created, mounted, updated, destroyed.Vue Router
Dynamic Routing:
path: '/user/:id' → Matches /user/123.this.$router.push({ name: 'profile', params: { id: 123 } }).*): Catch-all for 404s (should be last in routes).Vuex (State Management)
Core Concepts:
Best Practices:
Component Communication
$emit).this.$refs.child).Class & Style Binding
Object Syntax:
<div :class="{ active: isActive, 'text-danger': hasError }"></div>Array Syntax:
<div :class="[isActive ? 'active' : '', errorClass]"></div>Computed Properties vs. Methods
Vue CLI & Single-File Components (SFCs)
.vue files encapsulate <template>, <script>, and <style>.javascript const store = new Vuex.Store({ state: { count: 0 }, mutations: { increment(state) { state.count++; } }, actions: { incrementAsync({ commit }) { setTimeout(() => commit('increment'), 1000); } } }); ``html <div :class="classObj"></div> ` `javascript data: { classObj: { active: true, 'text-danger': false } } ``javascript const router = new VueRouter({ routes: [ { path: '/user', component: User, children: [ { path: 'profile', component: Profile }, { path: 'posts', component: Posts } ] } ] }); ``javascript Vue.component('custom-input', { props: ['value'], template: <input :value="value" @input="event.target.value)"> }); ``| Feature | Cookies | Local Storage | Session Storage |
|---|---|---|---|
| Lifetime | Configurable (expires) | Persistent | Tab session |
| Capacity | ~4KB | ~5MB | ~5MB |
| Access | Sent with HTTP requests | Client-side only | Client-side only |
| Use Case | Session management | Offline data | Temporary data |
| Security | Vulnerable to CSRF | XSS risk | XSS risk |
javascript localStorage.setItem('key', 'value'); const value = localStorage.getItem('key'); ``javascript sessionStorage.setItem('temp', 'data'); ``javascript document.cookie = "username=John; expires=Thu, 1 Jan 2025 00:00:00 UTC; path=/"; ``JavaScript:
this binding.&&, ||) and truthy/falsy values.Web Technologies:
Access-Control-Allow-Origin) and mitigation (anti-CSRF tokens).Vue.js:
*) should be last in routes.Celery/Redis:
delay() vs. apply_async(countdown=10):
delay(): Immediate dispatch.apply_async: Delayed dispatch (but not delayed execution unless countdown is set).Storage:
var: Always prefer const/let.credentials: 'include' for cross-origin cookies.* before specific routes (catches all early).let in for).| Value | Type | Truthy/Falsy |
|---|---|---|
false | boolean | Falsy |
0, -0, 0n | number | Falsy |
"", `, ` | string | Falsy |
null | object | Falsy |
undefined | undefined | Falsy |
NaN | number | Falsy |
| Everything else | - | Truthy |
| Hook | When Called |
|---|---|
beforeCreate | Before instance initialization |
created | After instance creation |
beforeMount | Before DOM insertion |
mounted | After DOM insertion |
beforeUpdate | Before reactive data updates DOM |
updated | After DOM updates |
beforeDestroy | Before teardown |
destroyed | After teardown |
| Code | Meaning |
|---|---|
| 200 | OK |
| 201 | Created |
| 400 | Bad Request |
| 401 | Unauthorized |
| 403 | Forbidden |
| 404 | Not Found |
| 500 | Internal Server Error |
Before the exam, ensure you can:
JavaScript:
.then()/.catch().this in arrow vs. regular functions.Web:
Vue.js:
Backend:
Storage: