Home / Past papers / MAD2 End Term / this paper

Suppose a script is downloaded from the origin 'http://example.com'. The script can not make a request to which of the following origins, assuming none of the origins allow cross-origin requests?

http://example.com/profile

http://new.example.com

http://example.com

http://new.example.com/profile
Which of the following shows the correct output if the javascript program written below is executed? ```javascript const a = [2, 5, 8, 11, 14, 17] const b = a.map(element => element ** 2) const c = b.filter(element => element % 2) const d = c.find(element => element % 3 == 1) console.log(d) ```
Which of the following shows the correct output if the javascript program written below is executed? ```javascript
async function demo () {
let prom = new Promise((res, rej) => {
setTimeout(() => res(40), 2000)
})
console.log("Statement 2") // Statement 2
return prom
}
demo().then(result => console.log(result))
console.log("Statement 1") // Statement 1
```
40 Statement 2 Statement 1

40 Statement 1 Statement 2

Statement 1 Statement 2 40

Statement 2 Statement 1 40
Consider the below application with markup “index.html” and javascript file “app.js”. Suppose the user clicks on buttons with text “3” and then “4”, what will be rendered inside the “Player” component?```html
index.html:
<body>
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="app.js" type="module"></script>
</body>
app.js:
const Player = {
template: `<div><div>{{ striker.name }}</div>
<div>{{ nonStriker.name }}</div>
</div>`,
data() {
return {
player1: { name: 'Rohit' },
player2: { name: 'Virat' },
}
},
props: {
run: { type: Number, default: 0 },
},
computed: {
striker() {
return this.run % 2 == 0 ? this.player1 : this.player2
},
nonStriker() {
return this.run % 2 == 1 ? this.player1 : this.player2
},
},
}
const Run = {
template: `<button @click="$emit('run-changed',
run)">{{ run }}</button>`,
props: { run: Number },
}
new Vue({
el: '#app',
template: `<div>
<Player :run='score'/>
<div style='display: flex'>
<Run :run="3" @run-changed = 'runChanged'/>
<Run :run="4" @run-changed = 'runChanged' />
</div>
</div>`,
components: { Run, Player },
data: {
score: 0,
},
methods: {
runChanged(run) {
this.score = run
},
},
})
```
Rohit* Virat

Virat* Rohit

Virat* Rohit*

Rohit* Virat*
Consider the below application with markup “index.html” and javascript file “app.js”. index.html:
```html
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
```
app.js:
```javascript
const data = {
1: { totalRun: 1000, totalMatches: 20 },
2: { totalRun: 7000, totalMatches: 100 },
}
const NotFound = { template: '<div> Player Not Found</div>' }
const Profile = {
template: `<div>Run: {{ {stat.totalRun}}, Matches:
{{stat.totalMatches}}, Average: {{average}}</div>`,
data() {
return {
stat: data[this.$route.params.id],
}
},
computed: {
average() {
return this.stat.totalRun / this.stat.totalMatches
},
},
}
const router = new VueRouter({
routes: [
{ path: '/profile/:id', component: Profile },
{ path: '*', component: NotFound },
],
})
new Vue({
el: '#app',
template: '<div><router-view /></div>',
router,
})
```
Suppose the application is running on "http://127.0.0.1:8080". What will be rendered inside the "router-view" component for the URL "http://127.0.0.1:8080/#/player"?
Consider the below application with markup “index.html” and javascript file “app.js”. index.html:
```html
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
```
app.js:
```javascript
const data = {
1: { totalRun: 1000, totalMatches: 20 },
2: { totalRun: 7000, totalMatches: 100 },
}
const NotFound = { template: '<div> Player Not Found</div>' }
const Profile = {
template: `<div>Run: {{stat.totalRun}}, Matches:
{{stat.totalMatches}}, Average: {{average}}</div>`,
data() {
return {
stat: data[this.$route.params.id],
}
},
computed: {
average() {
return this.stat.totalRun / this.stat.totalMatches
},
},
}
const router = new VueRouter({
routes: [
{ path: '/profile/:id', component: Profile },
{ path: '*', component: NotFound },
],
})
new Vue({
el: '#app',
template: '<div><router-view /></div>',
router,
})
```
Suppose the application is running on "http://127.0.0.1:8080". What will be displayed for the URL "http://127.0.0.1:8080/#/profile/1"?
Consider the below application with markup “index.html” and javascript file “app.js”. index.html:
```html
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const overs = {
1: [2, 3, 4, 6, 2],
2: [3, 2, 5, 3, 1],
}
const NotFound = { template: `<div> Over Not Found</div>` }
const MatchNotStarted = { template: `<div>Match has not yet started.</div>` }
const currentOver = {
template: `<div style='display: flex'>
<div v-for='run in over' style='padding: 10px'>{{run}}</div>
</div>`,
data() {
return {
over: overs[this.$route.params.overNo]
? overs[this.$route.params.overNo]
: overs[2],
}
},
}
const liveScore = {
template: `<div>Total Score:{{totalScore}} <router-view /></router-view></div>`,
data() {
return {
totalScore: 100,
}
},
}
const router = new VueRouter({
routes: [
{
path: '/live-score',
component: liveScore,
children: [
{ path: '', component: MatchNotStarted },
{ path: 'over/:overNo', component: currentOver },
],
},
],
})
new Vue({
el: '#app',
template: `<div><router-view /></div>`,
router,
})
```
Suppose the application is running on "http://127.0.0.1:8080". What will be rendered in the "router-view" component of the "live-score" component for URL "http://localhost:8080/#/live-score"?
Consider the below application with markup “index.html” and javascript file “app.js”. index.html:
```html
<body>
<div id="app"></div>
<script
src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script
src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const overs = {
1: [2, 3, 4, 6, 2],
2: [3, 2, 5, 3, 1],
}
const NotFound = { template: `<div> Over Not Found</div>` }
const MatchNotStarted = { template: `<div>Match has not yet started.</div>` }
const currentOver = {
template: `<div style='display: flex'>
<div v-for='run in over' style='padding: 10px'>{{run}}</div>
</div>`,
data() {
return {
over: overs[this.$route.params.overNo]
? overs[this.$route.params.overNo]
: overs[2],
}
},
}
const liveScore = {
template: `<div>Total Score:{{totalScore}} <router-view /></router-view></div>`,
data() {
return {
totalScore: 100,
}
},
}
const router = new VueRouter({
routes: [
{
path: '/live-score',
component: liveScore,
children: [
{ path: '', component: MatchNotStarted },
{ path: 'over/:overNo', component: currentOver },
],
},
],
})
new Vue({
el: '#app',
template: `<div><router-view /></div>`,
router,
})
```
Suppose the application is running on "http://127.0.0.1:8080". What will be rendered in the "router-view" component of the "live-score" component for URL "http://localhost:8080/#/live-score/over/2"?
Consider the below application with markup “index.html” and javascript file “app.js”. index.html:
```html
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/vue-router@3.0.0/dist/vue-router.js"></script>
<script src="app.js" type="module"></script>
</body>
```
app.js:
```javascript
const overs = {
1: [2, 3, 4, 6, 2],
2: [3, 2, 5, 3, 1],
}
const NotFound = { template: `<div> Over Not Found</div>` }
const MatchNotStarted = { template: `<div>Match has not yet started.</div>` }
const currentOver = {
template: `<div style='display: flex'>
<div v-for='run in over' style='padding: 10px'>{{run}}</div>
</div>`,
data() {
return {
over: overs[this.$route.params.overNo]
? overs[this.$route.params.overNo]
: overs[2],
}
},
}
const liveScore = {
template: `<div>Total Score:{{totalScore}} <router-view /></router-view></div>`,
data() {
return {
totalScore: 100,
}
},
}
const router = new VueRouter({
routes: [
{
path: '/live-score',
component: liveScore,
children: [
{ path: '', component: MatchNotStarted },
{ path: 'over/:overNo', component: currentOver },
],
},
],
})
new Vue({
el: '#app',
template: `<div><router-view /></div>`,
router,
})
```
Suppose the application is running on "http://127.0.0.1:8080". What will be rendered in the "router-view" component of the "live-score" component for URL "http://localhost:8080/#/live-score/over/20"?
Which of the following is/are not 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

```html <div :class="[isActive ? 'activeClass' : '', 'errorClass']"></div> ```

```html
<div :class="[{ 'activeClass' : isActive }, 'errorClass']"></div>
```
```html <div :class="[activeClass ? isActive : '', 'errorClass']"></div> ```

```html
<div :class="[{ isActive : 'activeClass' }, 'errorClass']"></div>
```
Suppose you are building an application which requires sending emails to all the users stored in the database at regular intervals. Given below are the two approaches to satisfy the requirement. Choose the correct statement(s).Approach 1:
```python
@celery.task
def send_bulk_emails():
all_users = User.query.all() // Get all the user objects from the
database
for user in all_users:
// send email to the user
send_bulk_emails.delay() // invokes celery task
```
Approach 2:
```python
@celery.task
def send_email(email):
// send email to the user
all_users = User.query.all() // Get all the user objects from the database
for user in all_users:
send_email.delay(user.email) // invokes celery task
```
Suppose an endpoint in your flask application triggers a celery task, which generates a CSV file named “data.csv” and saves it in the static folder of a flask application. The file generator takes anywhere between 20 and 40 seconds to generate and save the CSV file. The below fetch call is used to get the file generated by the above explained celery task. Which of the following is the most efficient way to make the above fetch call so that it doesn’t fail and return the desired response? ```javascript
fetch("/static/data.csv").then(response => response.blob())
.then(data => {
// does something with the response data
})
```
Consider the following Vue application with markup “index.html” and javascript file “app.js”. Suppose you open the “index.html” file in a browser. What will be rendered by the browser?index.html:
```html
<div id = "app">
<my-comp>
<template #header>
This is header content
</template>
<template #footer>
This is footer content
</template>
<p> This is some content </p>
</my-comp>
</div>
<script src = "app.js"></script>
```
app.js:
```javascript
Vue.component("myComp", {
template : `<div>
<p>
<slot name="header"></slot>
</p>
<p>
<slot></slot>
</p>
</div>`,
})
const app = new Vue({
el : "#app",
})
```
This is header content This is footer content This is some content

This is header content This is some content

This is header content

This is some content This is header content
Consider the following javascript program, and predict the output if executed. ```javascript
new Promise(((str1, str2) => {
if (5 == "5") str1(5)
else str2(8)
})).
then(d => {
console.log("Checkpoint 4", d);
throw new Error(20);
return d * 5;
})
.then(d => {
console.log("Checkpoint 2", d);
return d;
}, d => {
console.log("Checkpoint 1", d.message);
return d.message * 2;
}).catch(e => {
console.log("Checkpoint 3", e.message);
return e.message * 2;
}).finally(d => {
console.log("Checkpoint 6", d);
return d * 5;
}).then(d => {
console.log("Checkpoint 5", d);
return d * 5;
})
```
Checkpoint 4 5 Checkpoint 3 20 Checkpoint 1 undefined Checkpoint 6 NaN

Checkpoint 4 8 Checkpoint 1 20 Checkpoint 6 NaN Checkpoint 5 40

Checkpoint 4 5 Checkpoint 1 20 Checkpoint 6 undefined Checkpoint 5 40

Checkpoint 4 5 Checkpoint 5 20 Checkpoint 1 40 Checkpoint 6 200
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 “abhishekabhinavabhi” 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 = "text" @input = "save_data">
<p> {{content}} </p>
</div>
<script scr = "app.js"></script>
```
app.js:
```javascript
new Vue({
el : "#app",
data : {
text : "",
content : "",
},
mounted () {
try {
this.text = localStorage.getItem("value1").split("abhi").slice(1,
-1).join("");
this.content =
localStorage.getItem("value1").split("abhi").slice(1).join("");
}
catch {
this.text = "";
this.content = "";
}
},
methods : {
save_data() {
localStorage.setItem("value1", this.text);
localStorage.setItem("value2", this.content);
}
}
})
```
sheknav, sheknav

nav, nav

shek, sheknav

``` "", nav ```
Which of the following shows the correct output if the javascript program written below is executed? ```javascript
let num = 50
const a = {
num : 10,
func : function (num) {
console.log("Function A:", num)
}
}
const b = {
num : 20,
func : function () {
console.log("Function B:", this.num)
a.func.bind(this)(num = 40)
}
}
b.func.apply(a, [40])
```
Function B: 20 Function A: 10

Function B: 40 Function A: 40

Function B: 10 Function A: 10

Function B: 10 Function A: 40
Consider the below application with markup “index.html” and javascript file “app.js”. Suppose you open the file “index.html” in a browser. What will be rendered by the browser?index.html:
```html
<body>
<div id="app"></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',
template: `<div>
<ol type='1'>
<li v-for='fruit in fruits'>{{fruit}}</li>
</ol>
</div>`,
data: {
fruits: ['Banana', 'Mango'],
},
created() {
this.fruits.push('Orange')
},
mounted() {
this.fruits.push('Apple')
},
})
```
1) Banana 2) Mango

1) Banana 2) Mango 3) Orange

1) Banana 2) Mango 3) Apple

1) Banana 2) Mango 3) Orange 4) Apple
Consider the below application with markup “index.html” and javascript file “app.js”. Suppose you open the file “index.html” in a browser. What will be rendered inside the slot, by the browser?index.html:
```html
<body>
<div id="app"></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
const Player = {
template: `<div style='background-color:red'><slot></slot></div>`,
data() {
return {
scores: [
{ name: 'Rohit', run: 20 },
{ name: 'Virat', run: 50 },
],
}
},
}
new Vue({
el: '#app',
template: `<div>
<h1> Score Board</h1>
<Player>
<ol type='1'>
<li v-for='score in scores'>{{score.name}}:
{{score.run}}</li>
</ol>
</Player>
</div>`,
data: {
scores: [
{ name: 'Rohit', run: 50 },
{ name: 'Virat', run: 20 },
],
},
components: {
Player,
},
})
```
1) Rohit: 20 2) Virat: 50

1) Rohit: 50 2) Virat: 20

1) Rohit: 50 2) Virat: 50

1) Rohit: 20 2) Virat: 20
Consider the below flask application. app.py:
```python
from flask import Flask
from flask_caching import Cache
from time import sleep
config = {
"CACHE_TYPE": "RedisCache",
"CACHE_REDIS_URL": 'redis://localhost:6379/1'
}
app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
@cache.memoize(timeout=120)
def get_score(name):
sleep(10)
return 0
@app.route('/match/<int:match_id>/player/<name>/score')
def score(match_id, name):
score = get_score(name)
return f"IND Vs AUS- SKY: {score}"
if __name__ == '__main__':
app.run(debug=True)
```
If the Redis server is running on "localhost:6379", and application is running on "http://127.0.0.1:5000". If a user visits the URL "http://127.0.0.1:5000/match/1/player/sky/score" at 7AM in the morning for the first time and then at 9AM for the second time. What will be the approximate absolute difference between the response time of the requests?
Consider the below flask application. app.py:
```python
from flask import Flask
from flask_caching import Cache
from time import sleep
config = {
"CACHE_TYPE": "RedisCache",
"CACHE_REDIS_URL": 'redis://localhost:6379/1'
}
app = Flask(__name__)
app.config.from_mapping(config)
cache = Cache(app)
@cache.memoize(timeout=120)
def get_score(name):
sleep(10)
return 0
@app.route('/match/<int:match_id>/player/<name>/score')
def score(match_id, name):
score = get_score(name)
return f"IND Vs AUS- SKY: {score}"
if __name__ == '__main__':
app.run(debug=True)
```
If the Redis server is running on "localhost:6379", and application is running on "http://127.0.0.1:5000". If a user visits the URL "http://127.0.0.1:5000/match/1/player/sky/score" first and then "http://127.0.0.1:5000/match/2/player/sky/score" within 2 minutes. What will be the approximate absolute difference between the response time of the requests?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.
Hoisting:
var declarations are hoisted and initialized with undefined.let/const declarations are hoisted but not initialized (Temporal Dead Zone).Example:
console.log(x); // undefined (var)
console.log(y); // ReferenceError (let/const)
var x = 5;
let y = 10;Variable Scoping:
var: Function-scoped or global.let/const: Block-scoped.var, let, const) can declare globals if not in a block/function.First-Class Functions:
Functions can be:
Arrow Functions vs. Regular Functions:
Arrow functions:
this binding (lexical scoping).arguments object.Asynchronous JavaScript:
.then(), .catch(), .finally().Example:
async function demo() {
let prom = new Promise((res) => setTimeout(() => res(46), 2000));
console.log("Statement 2");
return prom;
}
demo().then((result) => console.log(result));
console.log("Statement 1");
// Output: "Statement 2", "Statement 1", 46this Binding:
.bind(), .call(), .apply() can override this.Example:
const obj = { num: 10 };
function func() { console.log(this.num); }
func.call(obj); // 10Cookies:
Expires/Max-Age).Strict, Lax, None).CORS (Cross-Origin Resource Sharing):
CORS Headers:
Access-Control-Allow-Origin: Specifies allowed origins.Access-Control-Allow-Methods: Allowed HTTP methods.Example:
Access-Control-Allow-Origin: http://example.comBrowser Sandbox:
Publisher-Subscriber Model:
Message Brokers (e.g., RabbitMQ, Kafka):
Features:
| Technique | Description | Pros | Cons |
|---|---|---|---|
| Short Polling | Client polls server at fixed intervals. | Simple to implement. | High latency, inefficient. |
| Long Polling | Server holds request until data is available or timeout occurs. | Lower latency than short polling. | Complex to implement. |
| WebSockets | Persistent full-duplex connection between client and server. | Real-time, low latency. | Requires WebSocket support. |
Key Differences:
Idempotency:
DELETE /users/1 is idempotent; POST /users is not.Statelessness:
beforeCreate → created → beforeMount → mounted → beforeUpdate → updated → beforeDestroy → destroyedComponents:
Directives:
v-if/v-show: Conditional rendering.v-for: Loop over arrays/objects.v-model: Two-way data binding.v-bind: Bind attributes (:class, :style).v-on: Listen to events (@click).Vue Router:
router-view: Renders matched component.router-link: Navigation links.Example:
const router = new VueRouter({
routes: [
{ path: '/profile/:id', component: Profile },
{ path: '*', component: NotFound }
]
});Vuex (State Management):
Example:
const store = new Vuex.Store({
state: { count: 0 },
mutations: {
increment(state) { state.count++; }
}
});Dynamic Class Binding:
:class="{ 'active': isActive }"Example:
<div :class="[isActive ? 'activeClass' : '', 'errorClass']"></div>| Proxy Type | Description | Use Cases |
|---|---|---|
| Forward Proxy | Acts on behalf of clients (hides client identities). | Bypass restrictions, cache requests. |
| Reverse Proxy | Acts on behalf of servers (hides server identities). | Load balancing, caching, security. |
Load Balancing:
Caching:
Asynchronous Task Execution:
Example:
@celery.task
def send_email(email):
# Send email logic
send_email.delay("user@example.com") # Enqueue taskWorkers:
Approach 1 (Bulk Task):
Approach 2 (Individual Tasks):
Polling for Task Status:
Flask-Caching:
Example:
@cache.memoize(timeout=120)
def get_score(name):
sleep(10) # Simulate slow operation
return 0
memoize: Caches based on function arguments.Redis:
Definition:
How It Works:
vs. WebSockets:
No mathematical equations were present in the questions, but here are key algorithmic concepts relevant to the exam:
Array Operations (JavaScript):
map: Transforms each element.
const b = a.map(x => x ** 2); // [4, 25, 64, ...]filter: Returns elements matching a condition.
const c = b.filter(x => x % 2); // Odd numbersfind: Returns the first element matching a condition.
const d = c.find(x => x % 3 === 1); // First odd number ≡ 1 mod 3Asynchronous Flow:
Promise chaining:
fetchData()
.then(data => process(data))
.catch(error => handle(error));Async/await:
async function fetch() {
const data = await fetchData();
console.log(data);
}Vue.js Reactivity:
Computed properties:
computed: {
average() {
return this.stat.totalRun / this.stat.totalMatches;
}
}JavaScript:
this binding, and async/await.map/filter/find chaining.Vue.js:
REST API:
Pub/Sub & Celery:
Proxies & Caching:
Webhooks:
Flask:
@cache.memoize and Redis integration.Good luck! Let me know if you'd like deeper dives into any topic.