MAD Study Hub

Home / Past papers / MAD2 End Term / this paper

IIT M IMPROVEMENT FN EXAM QDD2 01 Sep - 01 Sep 2024

MAD2 End Term32 questions100 marks24 MCQ · 8 MSQImprovement / forenoon / QDD2
Elapsed 00:00
Q1MCQ2 marks
What of the following is the primary objective of a CSRF token?
  1. To encrypt the user's session
  2. To validate that the request comes from the authenticated user
  3. To store the user's password securely
  4. To compress the HTTP request
Q2MCQ2 marks
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. question figure
    text
    https://api.example.com
  2. question figure
    text
    http://example.com/api
  3. question figure
    text
    https://example.com:8080
  4. question figure
    text
    https://example.com/subdir
Q3MCQ2 marks
What is the correct sequence of steps to update the state in Vuex when handling an asynchronous operation?
  1. State → Dispatch an action → Commit a mutation → State change
  2. Dispatch an action → Commit a mutation → State change
  3. Commit a mutation → Dispatch an action → State change
  4. State change → Commit a mutation → Dispatch an action
Q4MCQ3 marks
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. II, I, III
  2. III, I, II
  3. III, II, I
  4. I, II, III
Q5MCQ3 marks
Which of the following statements about Redis is true?
  1. Redis is a relational database that uses SQL for querying data.
  2. Redis is an in-memory data structure store, commonly used as a database,cache, and message broker.
  3. Redis can only store string data types and does not support complex datastructures like lists or sets.
  4. Redis cannot handle numerous operations per second.
Q6MCQ3 marks
Which of the following scenarios is an example of a Cross-Site Request Forgery (CSRF) attack?
  1. A user receives an email containing a link to a phishing site that asks for theirlogin credentials.
  2. A user clicks on a malicious link while logged into their bank account, andwithout their knowledge, a money transfer request is sent to the bank's server using the user'sauthenticated session.
  3. A hacker uses a brute-force attack to guess the password of a user's onlineaccount.
  4. A user is tricked into downloading and installing malware that steals theirsensitive information.
Q7MCQ3 marks
Match the following technologies with their typical use cases: question figure Match the following technologies with their typical use cases:
Text of the picture (copyable)
| | |
|---|---|
| 1. Webhooks | A. Real-time communication in chat applications |
| 2. Web Sockets | B. Fetching data periodically from an API endpoint |
| 3. API | C. Receiving notifications when a specific event occurs |
| 4. Polling | D. Exchanging data between client and server using HTTP requests |
| 5. Pub/Sub | E. Broadcasting messages to multiple subscribers simultaneously |
  1. 1 - C, 2 - A, 3 - D, 4 - B, 5 - E
  2. 1 - D, 2 - E, 3 - A, 4 - C, 5 - B
  3. 1 - C, 2 - C, 3 - E, 4 - A, 5 - D
  4. 1 - D, 2 - A, 3 - C, 4 - D, 5 - B
Q8MCQ3 marks
question figure
Text of the picture (copyable)
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. 2
  2. 1
  3. undefined
  4. Error
Q9MCQ3 marks
question figure
Text of the picture (copyable)
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. storedUsername: 'course_user', removedUsername: null, clearedStorage: null
  2. storedUsername: 'course_user', removedUsername: undefined,clearedStorage: null
  3. storedUsername: 'course_user', removedUsername: null, clearedStorage:undefined
  4. storedUsername: 'course_user', removedUsername: undefined,clearedStorage: undefined
Q10MCQ3 marks
question figure
Text of the picture (copyable)
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. regularResult = 40, arrowResult = 40
  2. regularResult = undefined, arrowResult = undefined
  3. regularResult = 40, arrowResult = undefined
  4. regularResult = undefined, arrowResult = 40
Q11MCQ3 marks
question figure
Text of the picture (copyable)
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. The approach 1 will toggle the page title between “Title A” and “Title B” afterevery 1 second (approx).
  2. The approach 2 will toggle the page title between “Title A” and “Title B” afterevery 1 second (approx).
  3. None of the approaches will toggle the page title after every 1 second.
  4. None of these
Q12MCQ3 marks
question figure
Text of the picture (copyable)
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. question figure
    text
    0
    1
    2
    3
    
    Minimum time taken will be: 15 sec
  2. question figure
    text
    1
    2
    3
    4
    
    Minimum time taken will be: 9 sec
  3. question figure
    text
    3
    3
    3
    3
    
    Minimum time taken will be: 6 sec
  4. question figure
    text
    4
    4
    4
    4
    
    Minimum time taken will be: 6 sec
Q13MSQ3 marksselect all that apply
Which of the following statement(s) is/are true about webhooks?
  1. Webhooks use HTTP requests to communicate events from one service toanother.
  2. Webhooks require the recipient service to periodically poll the sender forupdates.
  3. Webhooks are typically implemented using HTTP POST requests.
  4. Webhooks guarantee that events will be delivered in order and exactly once.
Q14MSQ3 marksselect all that apply
Which of the following statement(s) is/are true regarding javascript?
  1. Function declarations are hoisted along with their definitions.
  2. Variable declarations with var are hoisted with their initializations.
  3. let and const declarations are hoisted to the top of their block but remainuninitialized until execution reaches the declaration.
  4. Only function declarations are hoisted, not function definition.
Q15MSQ3 marksselect all that apply
Which of the following scenarios are best suited for using Celery tasks?
  1. Handling real-time user interactions on a website.
  2. Sending out periodic email notifications to users.
  3. Generating and displaying dynamic content on a web page.
  4. Performing long-running data processing tasks in the background.
Q16MSQ3 marksselect all that apply
Which of the following statements is/are true regarding webhooks and server sent events (SSE)?
  1. Webhooks are typically used for server-to-server communication, while SSE isused for server-to-client communication.
  2. Webhooks require the client to maintain an open connection to receiveupdates, while SSE does not.
  3. Webhooks are initiated by the server, while SSE connections are initiated bythe client.
  4. SSE supports bidirectional communication, whereas webhooks do not.
Q17MSQ3 marksselect all that apply
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
  1. question figure
    text
    ```html
    <div :class="[isActive ? 'activeClass' : 'errorClass']"></div>
    ```
  2. question figure
    text
    ```html
    <div :class="[{ isActive : 'activeClass' }, 'errorClass']"></div>
    ```
  3. question figure
    text
    ```html
    <div :class="[activeClass ? 'isActive' : '', 'errorClass']"></div>
    ```
  4. question figure
    text
    ```html
    <div :class="[{'activeClass': isActive }, 'errorClass']"></div>
    ```
Q18MSQ2 marksselect all that apply
Which of the following is/are true about Server-Sent Events (SSE)?
  1. SSE connections are established using HTTP.
  2. SSE supports bidirectional communication between client and server.
  3. SSE automatically switches to web socket if the connection is successful.
  4. SSE is suitable for sending updates to multiple clients simultaneously.
Q19MSQ2 marksselect all that apply
Which of the following HTTP header(s) can be used to control caching behavior in web applications?
  1. Cache-Control
  2. Expires
  3. Bearer
  4. Content-Type
Q20MSQ2 marksselect all that apply
Which of the following statement(s) is/are true regarding long and short polling?
  1. A webhook is the same as short polling.
  2. The short polling can be used to know the state of an asynchronous task, andtrigger an action if the task gets completed.
  3. The long polling cannot be achieved using HTTP protocol.
  4. Long Polling can be used to achieve real time communication.
Q21MCQ4.5 marks
Consider the following Vue.js 2 component using CDN. question figure Consider the following Vue.js 2 component using CDN. After entering "Orange" in the input box and clicking the "Add" button, what will be seen in the browser?
Text of the picture (copyable)
```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>
```
  1. 1. Apple2. Banana 3. Orange 4. Orange
  2. 1. Apple2. Banana 3. Orange
  3. 1. Apple2. Banana 3. Orange 3. Orange
  4. 1. Apple2. Banana
Q22MCQ4.5 marks
Consider the following javascript code running on browser question figure Consider the following javascript code running on browser What will be the output in the browser console?
Text of the picture (copyable)
```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'));
```
  1. 640
  2. null40
  3. 6null
  4. 0222null
Q23MCQ4.5 marks
question figure
Text of the picture (copyable)
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. Rex barkstrue true
  2. Rex barksfalse true
  3. Rex barks.true false
  4. Rex barks.false false
Q24MCQ4.5 marks
Consider the below flask application. question figure Consider the below flask application. 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?
Text of the picture (copyable)
```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. 5 seconds
  2. 0 seconds
  3. 10 seconds
  4. 180 seconds
Q25MCQ4.5 marks
Consider the below JavaScript program. question figure Consider the below JavaScript program. question figure Consider the below JavaScript program. What will be the output of the above program?
Text of the picture (copyable)
```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");
})
```
  1. Step 1: 0.6Step 2: 1.2 Step 4: 6.2 Step 6: Finally block executed
  2. Step 1: 0.6Step 3: Less than 0.75 Step 4: 1 Step 5: Fallback value Step 6: Finally block executed
  3. Step 1: 0.6Step 2: 1.2 Step 3: Error Step 4: 1 Step 5: Fallback value Step 6: Finally block executed
  4. Step 1: 0.6Step 3: Less than 0.75 Step 4: 1 Step 6: Finally block executed
Q26MCQ4.5 marks
In a Vue CLI project with Vuex, you have the following configuration: question figure In a Vue CLI project with Vuex, you have the following configuration: question figure In a Vue CLI project with Vuex, you have the following configuration:
Text of the picture (copyable)
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. question figure
    text
    API Value
  2. question figure
    text
    "" ""
  3. question figure
    text
    undefined
  4. question figure
    text
    null
Q27MCQ4.5 marks
question figure
Text of the picture (copyable)
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. “Network Error”
  2. “HTTP Error: 404”
  3. “Data is not JSON serializable”
  4. Data returned by the API
Q28MCQ4.5 marks
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? question figure
Text of the picture (copyable)
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)
```
  1. {“result” : 200} and {“result”: 50}
  2. {“result” : 50} and {“result”: 200}
  3. {“result”: 100} and {“result” : 100}
  4. {“result”: 200} and {“result”: 200}
Comprehension passage - the questions below it refer to this
Options: question figure Options: question figure Options: Based on the above data, answer the given subquestions. question figure
Q29MCQ3 marks
Which code snippet represents a Webhook receiver implementation?
  1. A
  2. B
  3. C
  4. D
Q30MCQ2 marks
Which code snippet represents a Pub/Sub implementation?
  1. A
  2. B
  3. C
  4. D
Comprehension passage - the questions below it refer to this
question figure question figure question figure
Q31MCQ3 marks
question figure
Text of the picture (copyable)
Suppose the application is running on port 8080.

What will be rendered inside router-view for the URL
"http://127.0.0.1:8080/#/profile/1235"?
  1. Page Not Found
  2. Unknown User
  3. Name: Animesh, State: MP
  4. Name: Arnav, State: Goa
Q32MCQ2 marks
question figure
Text of the picture (copyable)
Suppose the application is running
on port 8080. What will be rendered
inside router-view for the URL
"http://127.0.0.1:8080/#/profile/Arnav"?
  1. Page Not Found
  2. Name: Animesh, State: MP
  3. Name: Arnav, State: Goa
  4. Unknown User

Answer key

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

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



Core Topics & Concepts Summary

1. Web Security

2. Asynchronous JavaScript

3. State Management (Vuex)

4. Caching & Performance

5. Real-Time Communication

6. Task Queues (Celery)

7. Vue.js

8. Redis

9. HTTP & APIs

10. JavaScript Quirks


Key Equations (Mathematics/Algorithms)

(Limited in this exam, but included for completeness)

  1. Time Complexity of Polling

    • Short Polling: O(n) requests for n updates.
    • Long Polling: O(1) per update (server holds request until data is available).
  1. Cache Hit/Miss

    • Hit Rate: (Hits) / (Hits + Misses).
    • Flask-Caching: timeout=60 → Cache expires after 60 seconds.
  1. Asynchronous Task Delay

    • Example: setTimeout(fn, (i+1)*1500) → Delays of 1.5s, 3s, 4.5s, 6s.

2. Asynchronous JavaScript

3. Vuex State Management

4. Real-Time Communication

5. Caching Strategies

6. Vue.js Core Concepts


Exam Tips

  1. CSRF: Remember it’s about validating requests, not encrypting sessions.
  2. Same-Origin Policy: https://example.com and https://example.com:8080 are different origins (port matters).
  3. Vuex: Actions → Mutations → State (never mutate state directly).
  4. Closures: var in loops causes all timeouts to log the final value; use let.
  5. Caching: @cache.memoize caches based on function arguments; @cache.cached caches the entire view.
  6. Webhooks vs. Polling: Webhooks are event-driven; polling is client-initiated.
  7. Redis: In-memory store for caching, sessions, and Pub/Sub.
  8. Promise Chains: .catch handles rejections; .finally runs regardless of success/failure.