MAD Study Hub

Home / Past papers / MAD2 End Term / this paper

IIT M DIPLOMA FN EXAM QDD1 13 Apr 2025 - 13 Apr 2025

MAD2 End Term32 questions100 marks28 MCQ · 3 MSQ · 1 SADiploma / forenoon / QDD1
Elapsed 00:00
Q1MCQ2 marks
Which of the following statements is true regarding the "this" keyword in JavaScript?
  1. It always refers to the global object.
  2. Arrow functions have their own "this" context.
  3. "this" in an event listener always refers to the window object.
  4. None of these
Q2MCQ2 marks
Which of the following correctly describes the lifecycle of a Vue.js component?
  1. beforeCreate -> created -> beforeMount -> mounted -> beforeUpdate ->updated -> beforeUnmount -> unmounted
  2. beforeCreate -> created -> beforeMount -> beforeUpdate -> mounted ->updated -> beforeUnmount -> unmounted
  3. created -> beforeCreate -> beforeMount -> mounted -> updated ->beforeUnmount -> unmounted
  4. created -> beforeCreate -> beforeMount -> mounted -> beforeUnmount ->updated -> unmounted
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const promise = new Promise(((resolve, reject) => {
  resolve('Success!');
  reject('Failed!');
}));
promise.then(console.log).catch(console.log);
```

What will be the output of the above program?
  1. SuccessFailed
  2. Success
  3. Failed
  4. Error
Q4MCQ2 marks
Which of the following is NOT a common performance metric measured by Google Lighthouse?
  1. First Contentful Paint (FCP)
  2. Time to Interactive (TTI)
  3. Total Blocking Time (TBT)
  4. Database Query Time (DQT)
Q5MCQ2 marks
Which of the following is a key difference between Web Sockets and Server-Sent Events (SSE)?
  1. SSE allows bidirectional communication, while WebSockets only allow server-to-client communication.
  2. WebSockets maintain a persistent connection, while SSE creates a newconnection for each message.
  3. SSE works over HTTP and only supports server-to-client communication,whereas WebSockets provide full-duplex communication.
  4. WebSockets require an HTTP request for every message sent.
Q6MCQ2 marks
Which HTTP method is typically used for sending webhook notifications?
  1. GET
  2. POST
  3. DELETE
  4. PATCH
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
let arr = [1, 2, 3];
let sum = arr.reduce((acc, val, idx, array) => acc + array[idx + 1], 0);
console.log(sum);
```

What will be the output of the above program?
  1. 6
  2. NaN
  3. undefined
  4. 0
  5. NULL
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const obj = {
    num: 5,
    multiply: function () {
        return this.num * 2;
    }
};
const multiply = obj.multiply;
console.log(multiply());
```

What will be the output of the above program?
  1. 10
  2. undefined
  3. NaN
  4. NULL
  5. Error
Q9MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vuex store configuration:

```javascript
const store = new Vuex.Store({
  state: {
    items: [],
  },
  mutations: {
    addItem(state, item) {
      state.items.push(item);
    },
  },
  actions: {
    addItemAsync({ commit }, item) {
      setTimeout(() => {
        commit('addItem', item);
      }, 1000);
    },
  },
});
```

If the addItemAsync action is dispatched with the item 'Vue.js', what will be the state of items after 2 seconds?
  1. question figure
    text
    The image shows a single vertical bar character.
  2. question figure
    text
    ```
    ['Vue.js', 'Vue.js']
    ```
  3. question figure
    text
    ```
    ['Vue.js']
    ```
  4. question figure
    text
    [object]
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vue app.

```html
<div id="app">
  <router-link to="/foo">Go to Foo</router-link>
  <router-view></router-view>
</div>
<script>
  const Foo = { template: '<div>Foo</div>' };
  const Bar = { template: '<div>Bar</div>' };

  const routes = [
    { path: '/foo', component: Foo },
    { path: '/bar', component: Bar },
    { path: '/', component: Bar }
  ];

  const router = new VueRouter({ routes });

  new Vue({
    el: '#app',
    router
  });
</script>
```

What happens when the user clicks "Go to Foo"?
  1. Browser navigates to /foo and displays "Foo".
  2. Browser navigates to /foo but displays nothing.
  3. Error: No matching route.
  4. None of these
Q11MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Vue component using slots:

```
Vue.component("alert-box", {
  template: `
    <div class="alert-box">
      <strong><slot name="title">Default title</slot></strong>
      <slot>Default content</slot>
    </div>
  `,
});
```

How would you use this component to provide custom title and content in the slots?
  1. question figure
    text
    ```html
    <alert-box title="Custom Title">Custom content</alert-box>
    ```
  2. question figure
    text
    ```html
    <alert-box>
        <slot name="title">Custom Title</slot>Custom content
    </alert-box>
    ```
  3. question figure
    text
    ```html
    <alert-box>
        <template v-slot:title>
            Custom Title
        </template>
        Custom content
    </alert-box>
    ```
  4. question figure
    text
    ```html
    <alert-box>Custom Title - Custom content</alert-box>
    ```
Q12MCQ3 marks
Consider the following Vue component. question figure Consider the following Vue component.
Text of the picture (copyable)
```javascript
Vue.component('user-list', {
  data() {
    return {
      users: [
        { id: 1, name: 'Arbok', role: 'Admin' },
        { id: 2, name: 'Bayleaf', role: 'User' },
        { id: 3, name: 'Charzard', role: 'Moderator' }
      ]
    }
  },
  template: `
    <div>
      <slot name="header"></slot>
      <ul>
        <li v-for="user in users" :key="user.id">
          <slot :user="user">
            {{ user.name }}
          </slot>
        </li>
      </ul>
    </div>
  `
})
```
Which of the following is the correct way to use this component with a scoped slot?
  1. question figure
    text
    ```html
    <user-list v-slot="{ user }">
      <template>{{ user.name }} ({{ user.role }})</template>
    </user-list>
    ```
  2. question figure
    text
    ```html
    <user-list>
      <template v-slot:default="{ user }">
        {{ user.name }} ({{ user.role }})
      </template>
    </user-list>
    ```
  3. question figure
    text
    ```html
    <user-list>
        <template scope="{ user }">
            {{ user.name }} ({{ user.role }})
        </template>
    </user-list>
    ```
  4. question figure
    text
    ```html
    <user-list>
      <template slot-scope="{ user }">
        {{ user.name }} ({{ user.role }})
      </template>
    </user-list>
    ```
Q13MCQ3 marks
question figure
Text of the picture (copyable)
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);
```
  1. 10 30
  2. 10 undefined
  3. 10 20
  4. The program will raise an error
Q14MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Flask application (server.py):

server.py
```python
from flask import Flask
from flask_caching import Cache
import time

config = {
    "DEBUG": True,
    "CACHE_TYPE": "RedisCache",
    "CACHE_REDIS_URL": "redis://localhost:6379/1",
    "CACHE_DEFAULT_TIMEOUT": 300
}

app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)

@app.route('/data/<item>')
@cache.cached(timeout=100)
def get_data(item):
    time.sleep(25)
    return f"Data for {item}"

if __name__ == '__main__':
    app.run()
```

The application runs on http://localhost:5000.
A client makes two consecutive requests to http://localhost:5000/data/apple within 50 seconds
What will be the approximate absolute difference between their latencies?
  1. 25 seconds
  2. 35 seconds
  3. 0 seconds
  4. 15 seconds
Q15MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code.

```javascript
async function fetchData() {
  try {
    const response = await fetch('https://api.example.com/data');
    if (!response.ok) throw new Error('HTTP error');
    const data = response.json();
    return data;
  } catch (error) {
    if (error.name === 'TypeError') {
      return {
        status: 'network error'
      };
    }
    return {
      status: 'http error'
    };
  }
}
```

When the function is called, what will be returned if the request gives a 200 OK?
  1. question figure
    text
    ```
    { status: 'http error' }
    ```
  2. question figure
    text
    ```
    { status: 'network error' }
    ```
  3. question figure
    text
    JSON data
  4. question figure
    text
    The promise will remain pending
Q16MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code snippet. If the code is run on the browser,
what will be the output on the console?

```javascript
console.log("variable1")
setTimeout(() => {
    console.log("variable2")
    setTimeout(() => {
        console.log("variable3")
    }, 500);
}, 2000)
console.log("variable4")
```
  1. question figure
    text
    variable1
    variable2
    variable3
    variable4
  2. question figure
    text
    variable1
    variable4
    variable3
    variable2
  3. question figure
    text
    variable1
    variable4
    variable2
    variable3
  4. question figure
    text
    variable1
    variable3
    variable4
    variable2
Q17MCQ3 marks
Which of the following options is the correct sequence of steps in JWT authentication?
  1. Client sends credentials, server validates and responds with JWT, client storesJWT, client sends JWT with each request.
  2. Client sends credentials, server validates and stores session ID, client sendssession ID with each request.
  3. Client sends JWT, server validates and issues a new JWT for each request.
  4. Client sends JWT, server decrypts JWT and checks credentials again.
Q18MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below CORS enabled flask app.

```python
from flask import Flask
from flask_cors import CORS

app = Flask(__name__)
CORS(app, resources={r"/api/*": {"origins": "http://localhost:5000"}})

@app.route("/api/data")
def data():
    return {"message": "Hello from Flask"}
```

If a Vue.js frontend (simulation given below) at "http://localhost:3000" tries to fetch data, what will happen?

```javascript
fetch("http://localhost:5000/api/data")
    .then(response => response.json())
    .then(data => console.log(data));
```
  1. The request will be blocked due to CORS policy.
  2. The request will succeed and return { "message": "Hello from Flask" }.
  3. The request will fail because Vue.js does not support CORS.
  4. The server will crash due to incorrect CORS settings.
Q19MCQ4.5 marks
Consider the below Vuex setup. question figure Consider the below Vuex setup. What is logged to the console immediately after dispatching the action?
Text of the picture (copyable)
```javascript
const store = new Vuex.Store({
  state: {
    value: 0
  },
  mutations: {
    setValue(state, payload) {
      state.value = payload;
    }
  },
  actions: {
    async updateValue({
      commit
    }) {
      const newValue = await fetchData();
      commit('setValue', newValue);
    }
  }
});

function fetchData() {
  return new Promise(resolve => {
    setTimeout(() => resolve(42), 2000);
  });
}

store.dispatch('updateValue');
console.log(store.state.value);
```
  1. 0
  2. 42
  3. Undefined behavior
  4. Error: Action did not resolve
Q20MCQ4.5 marks
question figure
Text of the picture (copyable)
What will be logged to the console when the following JavaScript code runs?

```javascript
const alpha = [3, 5, 7, 9, 11, 13, 15, 17];
const beta = alpha.map(x => x ** 3);
const gamma = beta.filter(y => (y % 7 === 6) || (y % 5 === 4));
const delta = gamma.slice(0, 3);
console.log(delta);
```
  1. [27, 125, 343, 729, 1331]
  2. [125, 343, 729]
  3. [27, 125, 343]
  4. None of these
Q21MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Flask application (server.py) and an HTML file named index.html:

server.py

```python
from flask import Flask
import time

app = Flask(__name__)

@app.route("/api/slow1")
def slow_api_1():
    time.sleep(15)
    return "Response from Slow API 1", 200, {'Access-Control-Allow-Origin': '*'}

@app.route("/api/slow2")
def slow_api_2():
    time.sleep(25)
    return "Response from Slow API 2", 200, {'Access-Control-Allow-Origin': '*'}

if __name__ == "__main__":
    app.run(threaded=False)
```

index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Flask Fetch Example</title>
</head>
<body>
    <h1>Fetching API Data...</h1>

    <script>
        fetch("http://127.0.0.1:5000/api/slow1")
            .then(res => res.json())
            .then(data => console.log("API 1 Response:", data));

        fetch("http://127.0.0.1:5000/api/slow2")
            .then(res => res.json())
            .then(data => console.log("API 2 Response:", data));
    </script>
</body>
</html>
```

If you open index.html in a browser, approximately how long will it take for the second fetch call (http://127.0.0.1:5000/api/slow2) to complete and log the data to the console?
  1. 15 seconds
  2. 25 seconds
  3. 10 seconds
  4. 40 seconds
Q22MCQ4.5 marks
Consider the following Vue apps in script.js and the index.html file. question figure Consider the following Vue apps in script.js and the index.html file. What will be rendered on the browser?
Text of the picture (copyable)
script.js
```javascript
const app1 = new Vue({
  el: '#app1',
  data: {
    value1: "VueJS",
    value2: "Frontend"
  }
})
const app2 = new Vue({
  el: '#app2',
  data: {
    value3: "JavaScript"
  }
})
```

index.html
```html
<div id="app2">
  {{value1}}
  <div id="app1">
    {{value2}}
  </div>
  {{value3}}
</div>
<script src="./script.js"></script>
```
  1. Frontend
  2. VueJSFrontend
  3. VueJSJavaScript
  4. FrontendJavaScript
Q23MCQ4.5 marks
Consider the following Vue App and the HTML document given below. question figure Consider the following Vue App and the HTML document given below. What will be the output on the browser?
Text of the picture (copyable)
index.html
```html
<div id="app">
    <my-comp>
        <slot>Hello Frontend</slot>
        <slot>Hello VueJS</slot>
    </my-comp>
</div>
<script src="script.js"></script>
```

script.js
```javascript
const myComp = {
    template: `
        <div>
            <slot></slot>
            <slot></slot>
        </div>
    `
}

const app = new Vue({
    components: {
        "my-comp": myComp
    }
}).$mount('#app')
```
  1. Hello Frontend Hello Frontend
  2. Hello VueJS Hello VueJS
  3. Hello Frontend Hello Vue JS
  4. Hello Frontend Hello Vue JS Hello Frontend Hello Vue JS
Q24MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below flask implementation with JWT based authentication.

```python
from flask import Flask, request, jsonify
import jwt
import datetime

app = Flask(__name__)
SECRET_KEY = "supersecret"

def generate_token(user):
    return jwt.encode(
        {"user": user, "exp": datetime.datetime.utcnow() +
         datetime.timedelta(seconds=10)},
        SECRET_KEY,
        algorithm="HS256"
    )

@app.route("/login", methods=["POST"])
def login():
    user = request.json.get("user")
    token = generate_token(user)
    return jsonify({"token": token})

@app.route("/protected", methods=["GET"])
def protected():
    token = request.headers.get("Authorization").split(" ")[1]
    try:
        payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
        return jsonify({"message": f"Hello {payload['user']}!"})
    except jwt.ExpiredSignatureError:
        return jsonify({"error": "Token expired"}), 401
    except jwt.InvalidTokenError:
        return jsonify({"error": "Invalid token"}), 403
```

If a Vue.js client sends this request 15 seconds after login, what response will it receive
(assume the token sent is the one, which was received from login)?

```javascript
fetch("http://localhost:5000/protected", {
    method: "GET",
    headers: { "Authorization": "Bearer <JWT_TOKEN>" }
})
.then(res => res.json())
.then(console.log);
```
  1. question figure
    text
    ```json
    { "message": "Hello user!" }
    ```
  2. question figure
    text
    ```json
    { "error": "Token expired" }
    ```
  3. question figure
    text
    ```json
    {
      "error": "Invalid token"
    }
    ```
  4. question figure
    text
    ```json
    {
      "message": "Access granted"
    }
    ```
Q25MSQ2 marksselect all that apply
Which of the following is/are the correct usage of “v-for” directive in VueJS?
  1. item in array
  2. (item, index) of array
  3. (item, index) as array
  4. (item, index) in array
  5. Item of array
Q26MSQ2 marksselect all that apply
Which of the following are advantages of using GraphQL over REST?
  1. It allows clients to fetch only the required fields, reducing over-fetching.
  2. It replaces the need for authentication mechanisms.
  3. It improves database performance automatically.
  4. It enforces a strict API response format.
Q27MSQ3 marksselect all that apply
Which of the following statements are true regarding event loop in JavaScript?
  1. The event loop runs on a separate thread from the main JavaScript execution.
  2. The event loop allows JavaScript to perform non-blocking operations despitebeing single-threaded.
  3. Callbacks from setTimeout are placed in the task queue and executed after thecall stack is empty.
  4. All of these
Q28SA4.5 marks
question figure
Text of the picture (copyable)
Consider the below Vuex store configuration.

```javascript
const store = new Vuex.Store({
  state: {
    count: 0,
  },
  mutations: {
    increment(state) {
      state.count++;
    },
  },
});
```

And the below Vue component:

```html
<template>
  <div>
    <button @click="increment">Increment</button>
    <p>Count: {{ count }}</p>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex';

export default {
  computed: {
    ...mapState(['count']),
  },
  methods: {
    ...mapMutations(['increment']),
  },
};
</script>
```

What will be displayed in the placeholder "{{ count }}" on the browser after clicking the "Increment" button 3 times?
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q29MCQ3 marks
question figure
Text of the picture (copyable)
What will be the response
by the following fetch
request.

```javascript
fetch("http://127.0.0.1:5000/protected", {
    method: "GET"
})
.then(response => {
    return response.json();
})
.then(data => console.log("Protected Route Response:", data))
.catch(error => console.error("Error:", error));
```
  1. question figure
    text
    The request will be processed
    successfully, and "Hello,
    student!" will be returned.
  2. question figure
    text
    The request will fail with a
    401 Unauthorized error.
  3. question figure
    text
    The request will return an
    empty response with a 200
    OK status.
  4. question figure
    text
    The request will fail with a
    403 Forbidden error.
Q30MCQ3 marks
question figure
Text of the picture (copyable)
What will be the result of the following fetch request.

```javascript
fetch("http://127.0.0.1:5000/protected", {
    method: "GET",
    headers: {
        "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.."
    }
})
.then(response => {
    if (response.status === 403) {
        throw new Error("403 Forbidden: Insufficient permissions");
    }
    return response.json();
})
.then(data => console.log("Protected Route Response:", data))
.catch(error => console.error("Error:", error));
```
  1. question figure
    text
    The request will be processed
    successfully, and "Hello,
    student!" will be returned.
  2. question figure
    text
    The request will fail with a
    401 Unauthorized error.
  3. question figure
    text
    The request will return an
    empty response with a
    200 OK status.
  4. question figure
    text
    The request will fail with a
    403 Forbidden error.
Comprehension passage - the questions below it refer to this
Consider the following Vue app with the Vue Router shown below and answer the given subquestions. question figure Consider the following Vue app with the Vue Router shown below and answer the given subquestions. question figure Consider the following Vue app with the Vue Router shown below and answer the given subquestions.
Q31MCQ4.5 marks
What will be rendered on the browser if the application is loaded on the browser for the first time?
  1. You are not logged in.
  2. Welcome to profile
  3. You are not authorized.
  4. None of these.
Q32MCQ3 marks
What will be rendered on the browser for the given value of localStorage? question figure What will be rendered on the browser for the given value of localStorage?
Text of the picture (copyable)
```
{
  token: 112,
  userRole: "manager"
}
```
  1. You are not logged in.
  2. Welcome to profile
  3. You are not authorized.
  4. None of these.

Answer key

  1. Q1 (MCQ, 2 marks): D
  2. Q2 (MCQ, 2 marks): A
  3. Q3 (MCQ, 2 marks): B
  4. Q4 (MCQ, 2 marks): D
  5. Q5 (MCQ, 2 marks): C
  6. Q6 (MCQ, 2 marks): B
  7. Q7 (MCQ, 3 marks): B
  8. Q8 (MCQ, 3 marks): C
  9. Q9 (MCQ, 3 marks): B
  10. Q10 (MCQ, 3 marks): A
  11. Q11 (MCQ, 3 marks): C
  12. Q12 (MCQ, 3 marks): A
  13. Q13 (MCQ, 3 marks): C
  14. Q14 (MCQ, 3 marks): A
  15. Q15 (MCQ, 3 marks): D
  16. Q16 (MCQ, 3 marks): C
  17. Q17 (MCQ, 3 marks): A
  18. Q18 (MCQ, 3 marks): A
  19. Q19 (MCQ, 4.5 marks): A
  20. Q20 (MCQ, 4.5 marks): B
  21. Q21 (MCQ, 4.5 marks): D
  22. Q22 (MCQ, 4.5 marks): D
  23. Q23 (MCQ, 4.5 marks): D
  24. Q24 (MCQ, 4.5 marks): B
  25. Q25 (MSQ, 2 marks): A, D
  26. Q26 (MSQ, 2 marks): A
  27. Q27 (MSQ, 3 marks): B, C
  28. Q28 (SA, 4.5 marks): 3
  29. Q29 (MCQ, 3 marks): B
  30. Q30 (MCQ, 3 marks): D
  31. Q31 (MCQ, 4.5 marks): C
  32. Q32 (MCQ, 3 marks): B

Concepts this paper tests

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 core topics, concepts, and principles essential for the exam, along with key equations (where applicable) and Mermaid knowledge graphs to visualize relationships.



Core Topics & Concepts Summary

1. JavaScript Fundamentals


2. Vue.js


3. Web Technologies


4. Performance & Optimization


5. Debugging & Error Handling



Key Equations (Mathematics/Logic)

  1. Modulo Operations (Question 21):

    • y % 7 === 6: Checks if y leaves a remainder of 6 when divided by 7.
    • y % 5 === 4: Checks if y leaves a remainder of 4 when divided by 5.
    • Example: 27 % 7 = 6 (True), 125 % 5 = 0 (False).
  1. Array reduce Accumulation (Question 8):

    • acc + array[idx + 1]:

      • Iteration 1: 0 + 2 = 2
      • Iteration 2: 2 + 3 = 5
      • Iteration 3: 5 + undefined = NaN
  1. Asynchronous Timing (Question 22):

    • Sequential blocking requests:

      • /slow1 (15s) + /slow2 (25s) = 40s total (no threading).


Graph 2: Vue.js Ecosystem

Graph 3: Web Technologies

Graph 4: Performance Optimization


Exam Tips

  1. JavaScript:

    • Focus on this binding, event loop timing, and Promise states.
    • Practice reduce/map edge cases (e.g., undefined values).
  1. Vue.js:

    • Memorize lifecycle hooks and Vuex flow (state → mutations → actions).
    • Scoped slots and v-slot syntax are frequently tested.
  1. Web Tech:

    • Know the differences between WebSockets/SSE and when to use each.
    • CORS errors often appear in fetch requests.
  1. Performance:

    • Understand blocking vs. non-blocking in Flask (threading) and caching benefits.
  1. Debugging:

    • Check for missing return statements in async functions.
    • Vue reactivity requires proper state mutation methods.