Question 1
secure=False and samesite='Strict'
secure=True and samesite='None'
secure=True and samesite='Strict'
secure=False and samesite='Lax'
The IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 22 Dec 2024, in the September 2024 term, set QDF3: 32 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.
secure=False and samesite='Strict'
secure=True and samesite='None'
secure=True and samesite='Strict'
secure=False and samesite='Lax'
Correct answer
secure=True and samesite='Strict'
Which of the following is true regarding long polling?
Long polling opens multiple connections between the client and the server, and the server continuously sends updates to the client in real-time.
Long polling allows the client to make a single request to the server, where the server holds the connection open until new data is available and then sends the response.
Long polling involves the client repeatedly sending requests at fixed intervals to the server to check for updates, regardless of whether new data is available.
Long polling uses WebSockets to maintain a persistent, bidirectional connection between the client and the server.
Correct answer
Long polling allows the client to make a single request to the server, where the server holds the connection open until new data is available and then sends the response.
Given this Vue component structure:
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?
Correct answer
Consider the following JavaScript code snippet.
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))What will be the output on the console?
7
error
undefined
error4
Correct answer
error4
Consider the following JavaScript code snippet.
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?
Begin, Start, 5, End, Finish
Begin, Start, Finish, 5, End
Begin, Finish, Start, 5, End
Begin, Finish, Start, End, 5
Correct answer
Begin, Start, Finish, 5, End
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 :
<script src="https://otherurl.com/code.js"></script>Correct answer
Consider the below Vue component.
<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?
The paragraph with the text “This paragraph is hidden” will be displayed.
The paragraph with the text “This paragraph is visible” will be displayed.
Both paragraphs will be displayed because of the v-if and v-else bindings.
No change will happen, since v-if and v-else do not update the DOM.
Correct answer
The paragraph with the text “This paragraph is hidden” will be displayed.
Consider the below JavaScript program.
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?
Correct answer
Consider the below JavaScript program.
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?
Correct answer
Given the following routes configured in Vue Router, assuming that routes have been correctly configured in vue router.
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?
Home
Profile
Security
Settings
Correct answer
Security
Consider the below Vue component.
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?
The new value will be stored in session storage, and the “userName” data property will be updated.
The new value will be stored in session storage, but the “userName” data property will be reset to an empty string on page refresh.
The “userName” data property will be reset to an empty string, and the session storage value will be ignored on refresh.
The “userName” data property will not be updated in session storage because session storage doesn't persist across refreshes.
Correct answer
The new value will be stored in session storage, and the “userName” data property will be updated.
II, III, I
III, I, II
III, II, I
I, II, III
Correct answer
III, I, II
Which of the following statements is FALSE?
Cache-Control: no-store prevents caching
Data stored in sessionStorage remains available even after the browser is closed and reopened.
ETag helps validate cache freshness
localStorage has larger storage limit than cookies
Correct answer
Data stored in sessionStorage remains available even after the browser is closed and reopened.
Which of the following statements is false when using the “async” and “await” keywords in JavaScript?
The “await” keyword can only be used inside an async function.
The async functions run synchronously, but their await statements execute asynchronously.
The “await” keyword pauses the execution of the surrounding async function until the promise resolves.
The async functions always return a promise, even if the return value is not a promise.
Correct answer
The async functions run synchronously, but their await statements execute asynchronously.
Consider the below JavaScript program.
const obj = { name: "Abhi", greet: function() { console.log(this.name); }};
const greet = obj.greet;greet();What will be the output of the above program?
Correct answer
You have a Celery task send_email that needs to run every 10 minutes. How can you schedule it?
Using @app.task_periodic to run the task every 10 minutes.
Using @app.on_periodic to schedule a periodic task.
Using Celery Beat to schedule periodic tasks.
Celery doesn't support scheduling tasks at fixed intervals; you need to use an external scheduler.
Correct answer
Using Celery Beat to schedule periodic tasks.
Consider the following JavaScript code.
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?
Correct answer
Given the following Vuex store setup.
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?
this.$store.dispatch('incrementAsync');The increment mutation will be called immediately after the dispatch.
The incrementAsync action will be executed synchronously, and increment will be committed before the promise resolves.
The state will be updated after the asynchronous operation completes.
The action will be skipped since mutations cannot be called inside actions.
Correct answer
The state will be updated after the asynchronous operation completes.
Consider the below Vue app.
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”
The watcher will be triggered and log "User object changed: { name: 'Bob', age: 30 }".
The watcher will not be triggered because “name” is a nested property of “user” object.
The watcher will be triggered, but it will only log the new “name” value, i.e., “Dev”, and not the entire user object.
The watcher will throw an error because deep watching is not supported on nested objects.
Correct answer
The watcher will be triggered and log "User object changed: { name: 'Bob', age: 30 }".
Consider the following HTML, with included vue 2 cdn link.
<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 ?
[2, 4, 6]
[2, 4, 6, 8]
[4, 8, 12]
[2, 4, 6, 16]
Correct answer
[2, 4, 6, 8]
Consider the following html with appropriate vue 2 cdn link attached.
<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?
Required
Invalid format, Email exists, Required
Required, Email exists
Validating..., Required
Correct answer
Required
Consider the following python code snippet. Assuming proper configuration for caching is done, answer the question below.
from flask import Flask, requestfrom flask_caching import Cacheimport time
app = Flask(__name__)
app.config['CACHE_TYPE'] = 'RedisCache'app.config['CACHE_DEFAULT_TIMEOUT'] = 5cache = 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?
Correct answer
Consider the below Celery setup.
from celery import Celeryimport time
app = Celery('tasks', broker='redis://localhost:6379/0')
@app.taskdef 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)?
The task will immediately execute and print the result 'Task completed'.
The task will execute asynchronously, and 'Task completed' will be printed after a 10-second delay.
The task will execute synchronously, blocking the main thread for 10 seconds.
None of these
Correct answer
The task will execute asynchronously, and 'Task completed' will be printed after a 10-second delay.
Consider the following Vue application with markup index.html and JavaScript file script.js.
File: index.html
<div id="app"></div><script src="script.js"></script>File: script.js
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?
Correct answer
Consider the below Vue router configuration.
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?
Correct answers
Which of the following statements are true about Lighthouse?
Lighthouse measures various performance metrics, including Time to Interactive and Speed Index.
Lighthouse generates a single score for UI design only.
It can emulate network throttling and device types during performance evaluation.
Lighthouse focuses exclusively on performance and ignores accessibility.
Correct answers
Lighthouse measures various performance metrics, including Time to Interactive and Speed Index.
It can emulate network throttling and device types during performance evaluation.
Which of the following statement(s) is/are correct regarding the behavior of local storage in Vue.js applications?
The local storage data persists even after the browser is closed and reopened.
The local storage data is automatically cleared every session.
The local storage can only store strings, and storing objects requires manual serialization and de-serialization.
Vue's reactivity system automatically updates the local storage when bound to a Vue data property.
Correct answers
The local storage data persists even after the browser is closed and reopened.
The local storage can only store strings, and storing objects requires manual serialization and de-serialization.
The class, namely “classB” will always be applied to the div element.
The classes, namely “classA” and “classB” will always be applied to the div element.
The class, namely “classA” will only be applied to the div element, if the variable “isClassA” evaluates to true.
The class, namely “classB” will only be applied to the div element, if no variable with name “isClassA” exists.
Correct answers
The class, namely “classB” will always be applied to the div element.
The class, namely “classA” will only be applied to the div element, if the variable “isClassA” evaluates to true.
Which of the following statements correctly describe the use of asynchronous messaging systems and frameworks?
Celery allows web servers to offload long-running tasks to worker processes, decoupling task execution from user requests.
Push queues are used for real-time operations, while pull queues are better suited for batch processing.
Server-Sent Events (SSE) provide a persistent connection between server and client, enabling bi-directional communication.
Redis is a high-performance in-memory database that supports Pub/Sub.
Correct answers
Celery allows web servers to offload long-running tasks to worker processes, decoupling task execution from user requests.
Push queues are used for real-time operations, while pull queues are better suited for batch processing.
Redis is a high-performance in-memory database that supports Pub/Sub.
Which of the following statement(s) is/are true about Webhooks?
A Webhook is a method for a server to send real-time data to another server as an HTTP POST request.
Webhooks are typically used for sending periodic updates at regular intervals.
A client must continuously poll a Webhook URL to receive data.
Webhooks are usually used in event-driven architectures, where an event triggers an HTTP POST request to a specified endpoint.
Correct answers
A Webhook is a method for a server to send real-time data to another server as an HTTP POST request.
Webhooks are usually used in event-driven architectures, where an event triggers an HTTP POST request to a specified endpoint.
Which of the following statement(s) is/are true regarding Server-Sent Events (SSE) and WebSockets?
SSE is a two-way communication protocol, while WebSockets are
unidirectional.
WebSockets are more suited for scenarios requiring bi-directional communication.
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.
SSE is an extension of WebSockets, providing enhanced support for server-to- client communication.
Correct answers
WebSockets are more suited for scenarios requiring bi-directional communication.
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.
Which of the following is/are typical use case(s) for Celery tasks?
Processing time-consuming or resource-intensive background jobs asynchronously.
Directly handling incoming HTTP requests in web servers.
Scheduling periodic tasks like sending emails or cleaning up the database.
Serving real-time notifications over WebSockets.
Correct answers
Processing time-consuming or resource-intensive background jobs asynchronously.
Scheduling periodic tasks like sending emails or cleaning up the database.