MAD Study Hub

Home / Past papers / MAD2 End Term / this paper

IIT M IMPROVEMENT AN EXAM QDD4 22 - 22 Dec 2024

MAD2 End Term32 questions100 marks24 MCQ · 8 MSQImprovement / afternoon / QDD4
Elapsed 00:00
Q1MCQ3 marks
question figure
Text of the picture (copyable)
In the following code, which attributes ensure that the cookie will only be sent over HTTPS and restrict it from cross-site requests?

```
response.set_cookie('session_id', 'abc123', secure=option1, samesite=option2)
```
  1. secure=False and samesite='Strict'
  2. secure=True and samesite='None'
  3. secure=True and samesite='Strict'
  4. secure=False and samesite='Lax'
Q2MCQ3 marks
Which of the following is true regarding long polling?
  1. Long polling opens multiple connections between the client and the server,and the server continuously sends updates to the client in real-time.
  2. Long polling allows the client to make a single request to the server, where theserver holds the connection open until new data is available and then sends the response.
  3. Long polling involves the client repeatedly sending requests at fixed intervalsto the server to check for updates, regardless of whether new data is available.
  4. Long polling uses WebSockets to maintain a persistent, bidirectionalconnection between the client and the server.
Q3MCQ3 marks
question figure
Text of the picture (copyable)
Given this Vue component structure:

```javascript
Vue.component('child', {
  template: `
    <div>
      <slot name="header" :info="info"></slot>
      <slot :info="info"></slot>
    </div>
  `,
  data() {
    return {
      info: { title: 'Hello', desc: 'World' }
    }
  }
})
```

Which slot usage is correct?
  1. question figure
    text
    ```html
    <template v-slot:header="data">{{data.title}}</template>
    ```
  2. question figure
    text
    ```html
    <template v-slot:header>{{info.title}}</template>
    ```
  3. question figure
    text
    ```html
    <template v-slot:header="{ info }">{{info.title}}</template>
    ```
  4. question figure
    text
    ```html
    <template v-slot:header=info>{{info.title}}</template>
    ```
Q4MCQ3 marks
What will be the output on the console? question figure
Text of the picture (copyable)
Consider the following JavaScript code snippet.

```javascript
Promise.resolve(1)
  .then(x => x + 1)
  .then(x => Promise.resolve(x + 1))
  .then(x => { throw 'error' })
  .catch(e => e + 4)
  .then(x => console.log(x))
```
  1. 7
  2. error
  3. undefined
  4. error4
Q5MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code snippet.

```javascript
async function test() {
  console.log("Start");
  const val = await Promise.resolve(5);
  console.log(val);
  return "End";
}

console.log("Begin");
test().then(data => console.log(data));
console.log("Finish");
```

What will be the output sequence?
  1. Begin, Start, 5, End, Finish
  2. Begin, Start, Finish, 5, End
  3. Begin, Finish, Start, 5, End
  4. Begin, Finish, Start, End, 5
Q6MCQ3 marks
question figure
Text of the picture (copyable)
What will happen if a page includes this CSP header and the script attempts to load an external JavaScript file from otherurl.com?

**CSP Header:**

```
Content-Security-Policy: default-src 'self';
```

**HTML :**

```html
<script src="https://otherurl.com/code.js"></script>
```
  1. question figure
    text
    The script from otherurl1.com will load normally.
  2. question figure
    text
    The browser will display a warning and allow the script to load.
  3. question figure
    text
    Nothing will happen; the CSP only affects inline scripts.
  4. question figure
    text
    The script will fail to load, and an error will be logged in the console.
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vue component.

```html
<template>
  <div>
    <p v-if="isVisible">This paragraph is visible</p>
    <p v-else>This paragraph is hidden</p>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        isVisible: true
      };
    }
  };
</script>
```

What will happen when “this.isVisible = false” is executed?
  1. The paragraph with the text “This paragraph is hidden” will be displayed.
  2. The paragraph with the text “This paragraph is visible” will be displayed.
  3. Both paragraphs will be displayed because of the v-if and v-else bindings.
  4. No change will happen, since v-if and v-else do not update the DOM.
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
console.log("Start");

setTimeout(function() {
  console.log("Inside Timeout");
}, 0);

Promise.resolve().then(function() {
  console.log("Inside Promise");
});

console.log("End");
```

What will be the output of the above program?
  1. question figure
    text
    Start
    Inside Timeout
    Inside Promise
    End
  2. question figure
    text
    Start
    End
    Inside Promise
    Inside Timeout
  3. question figure
    text
    Start
    Inside Promise
    Inside Timeout
    End
  4. question figure
    text
    Start
    End
    Inside Timeout
    Inside Promise
Q9MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
function Person(name) {
  this.name = name;
}

Person.prototype.greet = function() {
  console.log("Hello, " + this.name);
};

const john = new Person("John");
john.greet();

delete john.greet;
john.greet();
```

What will be the output of the above program?
  1. question figure
    text
    Hello, John
    TypeError: john.greet is not a function
  2. question figure
    text
    Hello, John
    Hello, undefined
  3. question figure
    text
    Hello, John
    Hello, John
  4. question figure
    text
    TypeError: john.greet is not a function
    TypeError: john.greet is not a function
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Given the following routes configured in Vue Router, assuming that routes have
been correctly configured in vue router.

```javascript
const routes = [
  { path: '/', component: Home },
  { path: '/profile/:userId', component: Profile },
  { path: '/settings', component: Settings },
  { path: '/settings/security', component: Security },
  { path: '/*', component: NotFound },
];
```

Which route will match the path /settings/security?
  1. Home
  2. Profile
  3. Security
  4. Settings
Q11MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vue component.

```javascript
export default {
  data() {
    return {
      userName: '',
    };
  },
  mounted() {
    this.userName = sessionStorage.getItem('userName') || '';
  },
  watch: {
    userName(newVal) {
      sessionStorage.setItem('userName', newVal);
    }
  }
};
```

What will happen when the user enters a new value for "userName" and refreshes the page?
  1. The new value will be stored in session storage, and the “userName” dataproperty will be updated.
  2. The new value will be stored in session storage, but the “userName” dataproperty will be reset to an empty string on page refresh.
  3. The “userName” data property will be reset to an empty string, and thesession storage value will be ignored on refresh.
  4. The “userName” data property will not be updated in session storage becausesession storage doesn't persist across refreshes.
Q12MCQ3 marks
question figure
Text of the picture (copyable)
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, III, I
  2. III, I, II
  3. III, II, I
  4. I, II, III
Q13MCQ2 marks
Which of the following statements is FALSE?
  1. Cache-Control: no-store prevents caching
  2. Data stored in sessionStorage remains available even after the browser isclosed and reopened.
  3. ETag helps validate cache freshness
  4. localStorage has larger storage limit than cookies
Q14MCQ2 marks
Which of the following statements is false when using the “async” and “await” keywords in JavaScript?
  1. The “await” keyword can only be used inside an async function.
  2. The async functions run synchronously, but their await statements executeasynchronously.
  3. The “await” keyword pauses the execution of the surrounding async functionuntil the promise resolves.
  4. The async functions always return a promise, even if the return value is not apromise.
Q15MCQ2 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const obj = {
  name: "Abhi",
  greet: function() {
    console.log(this.name);
  }
};

const greet = obj.greet;
greet();
```

What will be the output of the above program?
  1. question figure
    text
    Abhi
  2. question figure
    text
    null
  3. question figure
    text
    Reference Error
  4. question figure
    text
    Garbage Value
  5. question figure
    text
    undefined
Q16MCQ2 marks
You have a Celery task send_email that needs to run every 10 minutes. How can you schedule it?
  1. Using @app.task_periodic to run the task every 10 minutes.
  2. Using @app.on_periodic to schedule a periodic task.
  3. Using Celery Beat to schedule periodic tasks.
  4. Celery doesn't support scheduling tasks at fixed intervals; you need to use anexternal scheduler.
Q17MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code.

```javascript
function addItemToCart(item) {
    let cart = JSON.parse(localStorage.getItem('cart')) || [];
    cart.push(item);
    localStorage.setItem('cart', JSON.stringify(cart));
}

function getCartItems() {
    return JSON.parse(localStorage.getItem('cart')) || [];
}

addItemToCart({ id: 1, name: 'Laptop' }.name);
console.log(getCartItems());
```

The above code is initially loaded on the browser and then the browser is refreshed two times.
What will be the final output?
  1. question figure
    text
    The image shows a single vertical bar character.
  2. question figure
    text
    ```
    [{ id: 1, name: 'Laptop' }]
    ```
  3. question figure
    text
    [undefined]
  4. question figure
    text
    ```
    ['Laptop', 'Laptop', 'Laptop']
    ```
Q18MCQ4.5 marks
question figure
Text of the picture (copyable)
Given the following Vuex store setup.

```javascript
const store = new Vuex.Store({
  state: {
    counter: 0
  },
  mutations: {
    increment(state) {
      state.counter++;
    }
  },
  actions: {
    async incrementAsync({
      commit
    }) {
      await new Promise(resolve => setTimeout(resolve, 1000));
      commit('increment');
    }
  }
});
```

Assuming the store is correctly binded with a Vue app, what will be the correct behavior when the following code is executed?

```javascript
this.$store.dispatch('incrementAsync');
```
  1. The increment mutation will be called immediately after the dispatch.
  2. The incrementAsync action will be executed synchronously, and increment willbe committed before the promise resolves.
  3. The state will be updated after the asynchronous operation completes.
  4. The action will be skipped since mutations cannot be called inside actions.
Q19MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below Vue app.

```javascript
new Vue({
  el: '#app',
  data: {
    user: {
      name: 'Abhi',
      age: 30
    }
  },
  watch: {
    user: {
      handler(newValue, oldValue) {
        console.log('User object changed:', newValue);
      },
      deep: true
    }
  }
});
```

What will happen if the following code is executed?

`app.user.name = "Dev"`
  1. The watcher will be triggered and log "User object changed: { name: 'Bob',age: 30 }".
  2. The watcher will not be triggered because “name” is a nested property of“user” object.
  3. The watcher will be triggered, but it will only log the new “name” value, i.e.,“Dev”, and not the entire user object.
  4. The watcher will throw an error because deep watching is not supported onnested objects.
Q20MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following HTML, with included vue 2 cdn link.

```html
<div id="app">{{doubledItems}}</div>
<script>
  new Vue({
    el: '#app',
    data() {
      return {
        items: [1, 2, 3],
        processed: []
      };
    },
    computed: {
      doubledItems() {
        return this.items.map(x => x * 2);
      }
    },
    created() {
      this.processItems();
    },
    methods: {
      processItems() {
        this.items.push(4);
        this.processed = this.doubledItems;

        setTimeout(() => {
          this.processed = this.processed.map(x =>
            this.doubledItems.includes(x) ? x : x * 2
          );
        }, 0);
      }
    }
  });
</script>
```

What will be displayed ?
  1. [2, 4, 6]
  2. [2, 4, 6, 8]
  3. [4, 8, 12]
  4. [2, 4, 6, 16]
Q21MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following html with appropriate vue 2 cdn link attached.

```html
<div id="app"></div>
<script>
  new Vue({
    el: '#app',
    template: `
      <div>
        <form @submit.prevent>
          <input v-model="email" @input="validateEmail">
          <button type="submit">Submit</button>
          <p>Errors: {{ displayErrors.join(', ') }}</p>
        </form>
      </div>
    `,
    data() {
      return {
        email: '',
        errors: [],
        validating: false,
        existingEmails: ['test@test.com', 'example@example.com']
      };
    },
    computed: {
      displayErrors() {
        return this.validating ? ['Validating...'] :
          this.errors;
      }
    },
    methods: {
      validateEmail() {
        this.validating = true;
        this.errors = [];

        if (!this.email.includes('@')) {
          this.errors.push('@ not present');
        }
        if (!this.email.includes('.')) {
          this.errors.push('invalid format');
        }

        if (this.existingEmails.includes(this.email)) {
          this.errors.push('Email exists');
        }

        this.validating = false;
      }
    },
    watch: {
      email(value) {
        if (!value) this.errors = ['Required']
      }
    }
  });
</script>
```

When typing "test@test.com" and then deleting it all, what is shown in the "Errors" paragraph at the end?
  1. Required
  2. Invalid format, Email exists, Required
  3. Required, Email exists
  4. Validating..., Required
Q22MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following python code snippet. Assuming proper configuration for caching is done, answer the question below.

```python
from flask import Flask, request
from flask_caching import Cache
import time

app = Flask(__name__)

app.config['CACHE_TYPE'] = 'RedisCache'
app.config['CACHE_DEFAULT_TIMEOUT'] = 5
cache = Cache(app)

@app.route('/time')
@cache.cached()
def get_time():
    return str(time.time())
```

Suppose the following sequence of requests is made:
Request 1: GET /time at 00:00:00
Request 2: GET /time at 00:00:02
Request 3: GET /time at 00:00:06
What will the responses be for each request?
  1. question figure
    text
    Request 1: 00:00:00
    Request 2: 00:00:02
    Request 3: 00:00:06
  2. question figure
    text
    Request 1: 00:00:00
    Request 2: 00:00:02
    Request 3: 00:00:02
  3. question figure
    text
    Request 1: 00:00:00
    Request 2: 00:00:00
    Request 3: 00:00:00
  4. question figure
    text
    Request 1: 00:00:00
    Request 2: 00:00:00
    Request 3: 00:00:06
Q23MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below Celery setup.

```python
from celery import Celery
import time

app = Celery('tasks', broker='redis://localhost:6379/0')

@app.task
def long_task():
    time.sleep(10)
    return 'Task completed'
```

What will be the result of calling long_task.delay() (assuming more than 1 worker are available)?
  1. The task will immediately execute and print the result 'Task completed'.
  2. The task will execute asynchronously, and 'Task completed' will be printedafter a 10-second delay.
  3. The task will execute synchronously, blocking the main thread for 10 seconds.
  4. None of these
Q24MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup index.html and JavaScript file script.js.

File: index.html
```html
<div id="app"></div>
<script src="script.js"></script>
```

File: script.js
```javascript
new Vue({
    el: '#app',
    template: `<div>
        Status: {{message}}<br>
        ETA: {{ETA}}
    </div>`,

    data: {
        message: "",
        ETA: 10,
    },

    beforeCreate() {
        this.message += "DOM Creating,"
        this.ETA -= 1
    },

    created() {
        this.message += "DOM Created,"
        this.ETA -= 1
    },

    beforeMount() {
        this.message += "DOM Mounting,"
        this.ETA -= 1
    },

    mounted() {
        this.message += "DOM Mounted"
        this.ETA -= 1
    },
})
```

Suppose the application is running on http://127.0.0.1:8080. What will be rendered by the browser?
  1. question figure
    text
    Status: DOM Mounted
    ETA: 9
  2. question figure
    text
    Status: DOM Mounting, DOM Mounted
    ETA: 8
  3. question figure
    text
    Status: DOM Created, DOM Mounting, DOM Mounted
    ETA: 7
  4. question figure
    text
    Status: DOM Creating, DOM Created, DOM Mounting, DOM Mounted
    ETA: 6
Q25MSQ2 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the below Vue router configuration.

```javascript
const routes = [
  {
    path: '/user/:id',
    component: UserProfile
  }
];

const router = new VueRouter({
  routes
});
```

Which of the following is a valid way to access the "id" parameter inside the UserProfile component?
  1. question figure
    text
    ```
    this.$router.params.id
    ```
  2. question figure
    text
    ```
    this.$route.query.id
    ```
  3. question figure
    text
    ```
    this.$route.params.id
    ```
  4. question figure
    text
    ```
    this.$route.params['id']
    ```
Q26MSQ2 marksselect all that apply
Which of the following statements are true about Lighthouse?
  1. Lighthouse measures various performance metrics, including Time toInteractive and Speed Index.
  2. Lighthouse generates a single score for UI design only.
  3. It can emulate network throttling and device types during performanceevaluation.
  4. Lighthouse focuses exclusively on performance and ignores accessibility.
Q27MSQ2 marksselect all that apply
Which of the following statement(s) is/are correct regarding the behavior of local storage in Vue.js applications?
  1. The local storage data persists even after the browser is closed and reopened.
  2. The local storage data is automatically cleared every session.
  3. The local storage can only store strings, and storing objects requires manualserialization and de-serialization.
  4. Vue's reactivity system automatically updates the local storage when bound toa Vue data property.
Q28MSQ2 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the below Vue class binding and select the most appropriate option(s).

```html
<div v-bind:class="[isClassA ? classA : '', classB]"></div>
```
  1. The class, namely “classB” will always be applied to the div element.
  2. The classes, namely “classA” and “classB” will always be applied to the divelement.
  3. The class, namely “classA” will only be applied to the div element, if thevariable “isClassA” evaluates to true.
  4. The class, namely “classB” will only be applied to the div element, if no variablewith name “isClassA” exists.
Q29MSQ3 marksselect all that apply
Which of the following statements correctly describe the use of asynchronous messaging systems and frameworks?
  1. Celery allows web servers to offload long-running tasks to worker processes,decoupling task execution from user requests.
  2. Push queues are used for real-time operations, while pull queues are bettersuited for batch processing.
  3. Server-Sent Events (SSE) provide a persistent connection between server andclient, enabling bi-directional communication.
  4. Redis is a high-performance in-memory database that supports Pub/Sub.
Q30MSQ3 marksselect all that apply
Which of the following statement(s) is/are true about Webhooks?
  1. A Webhook is a method for a server to send real-time data to another serveras an HTTP POST request.
  2. Webhooks are typically used for sending periodic updates at regular intervals.
  3. A client must continuously poll a Webhook URL to receive data.
  4. Webhooks are usually used in event-driven architectures, where an eventtriggers an HTTP POST request to a specified endpoint.
Q31MSQ3 marksselect all that apply
Which of the following statement(s) is/are true regarding Server-Sent Events (SSE) and WebSockets?
  1. SSE is a two-way communication protocol, while WebSockets areunidirectional.
  2. WebSockets are more suited for scenarios requiring bi-directionalcommunication.
  3. SSE is based on HTTP and can only be used for server-to-client communication,while WebSockets are based on TCP and support both directions.
  4. SSE is an extension of WebSockets, providing enhanced support for server-to-client communication.
Q32MSQ3 marksselect all that apply
Which of the following is/are typical use case(s) for Celery tasks?
  1. Processing time-consuming or resource-intensive background jobsasynchronously.
  2. Directly handling incoming HTTP requests in web servers.
  3. Scheduling periodic tasks like sending emails or cleaning up the database.
  4. Serving real-time notifications over WebSockets.

Answer key

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

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, principles, and equations for the "Diploma Level: Modern Application Development II" exam, along with Mermaid knowledge graphs to visualize relationships.



Core Topics & Concepts Summary

1. Web Security & Cookies

Key Concepts:

Equations/Code Snippets:

// Secure cookie (HTTPS + SameSite)
response.set_cookie('session_id', 'abc123', secure=True, samesite='Strict');

// CSP Header
Content-Security-Policy: default-src 'self';

2. Asynchronous JavaScript

Key Concepts:

Equations/Code Snippets:

// Promise chaining
Promise.resolve(1)
  .then(x => x + 1)
  .then(x => { throw 'error' })
  .catch(e => console.log(e + 4)); // Output: "error4"

// Async/Await
async function fetchData() {
  const data = await apiCall(); // Pauses until resolved
  return data;
}

3. Vue.js Core Concepts

Key Concepts:

Equations/Code Snippets:

<!-- Scoped Slot -->
<child v-slot:header="{ info }">
  {{ info.title }}
</child>

<!-- Vuex Action -->
actions: {
  async fetchData({ commit }) {
    const data = await apiCall();
    commit('SET_DATA', data);
  }
}

4. Real-Time Communication

Key Concepts:

Equations/Code Snippets:

// WebSocket Client
const socket = new WebSocket('wss://example.com');
socket.onmessage = (e) => console.log(e.data);

// SSE Client
const eventSource = new EventSource('/updates');
eventSource.onmessage = (e) => console.log(e.data);

5. Caching & Performance

Key Concepts:

Equations/Code Snippets:

### Celery Periodic Task
from celery.schedules import crontab
app.conf.beat_schedule = {
    'every-10-minutes': {
        'task': 'tasks.send_email',
        'schedule': 600.0,  # 10 minutes
    },
}

6. Storage & State Management

Key Concepts:

Equations/Code Snippets:

// Persist Vuex state
watch: {
  user(newVal) {
    localStorage.setItem('user', JSON.stringify(newVal));
  }
}

7. HTTP & APIs

Key Concepts:



2. Vue.js Lifecycle Hooks

3. Vuex Data Flow

4. Real-Time Technologies Comparison

5. Celery Task Queue

6. Storage Mechanisms



Key Equations/Code Snippets Recap

TopicEquation/Code
Secure Cookiesecure=True, samesite='Strict'
Promise Chaining.then().catch()
Vue Scoped Slot<template v-slot:header="{ info }">
Vuex Actionasync increment({ commit }) { await delay(); commit('INCREMENT'); }
WebSocket Clientnew WebSocket('wss://example.com')
Celery Periodic Task@app.task\n@periodic_task(run_every=crontab(minute='*/10'))
CSP HeaderContent-Security-Policy: default-src 'self'
localStoragelocalStorage.setItem('key', JSON.stringify(data))