MAD Study Hub

Home / Past papers / MAD2 Quiz 2 / this paper

IIT M FOUNDATION AN2 EXAM QPF2 06 Aug 2023 - 06 Aug 2023

MAD2 Quiz 216 questions50 marks12 MCQ · 4 MSQFoundation / QPF2
Elapsed 00:00
Q1MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
function data(d) {
  return new Promise((res) => {
    setTimeout(() => res('Your Data'), d * 1000)
  })
}

function delta(d) {
  return new Promise((res) => {
    if (d > 3) {
      setTimeout(() => res('delta'), d * 500)
    } else {
      return res('delta')
    }
  })
}

async function getData(d) {
  const start = Date.now()
  const _delta = await delta(d)
  const _data = await data(d)
  const end = Date.now()
  const timeDifference = end - start
}

getData(4)
```

What will be the approximate value of the variable "timeDifference"?
  1. Less than 4000
  2. Is equal to 4000
  3. Greater than or equal to 6000
  4. None of these
Q2MCQ3 marks
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Text of the picture (copyable)
app.js:
```javascript
const Teams = {
  template: `<ol><li v-for='team in
  teams'>{{team.name}}</li></ol>`,
  data() {
    return {
      teams: [
        { name: 'India', points: 827 },
        { name: 'Australia', points: 820 },
      ],
    }
  },
}

const Rankings = {
  template: `<ol><li v-for='team in sortedTeams'>
  {{team.name}}</li></ol>`,
  data() {
    return Teams.data()
  },
  computed: {
    sortedTeams() {
      return this.teams.sort((team1, team2) => {
        return team1.points - team2.points // Statement 1
      })
    },
  },
}

const router = new VueRouter({
  routes: [
    { path: '/', component: Teams },
    { path: '/ranking', component: Rankings },
  ],
})

new Vue({
  el: '#app',
  template: `<div> <router-view /> </div>`,
  router,
})
```

index.html:
```html
<div id="app"></div>
```

Suppose the application is running on "http://localhost:8080". If the developer wants to display the teams in descending order with respect to the points of team, for the URL "http://localhost:8080/#/ranking". What should be the value of return statement in "sortedTeams" computed property (Marked by statement1)?
  1. team1.points - team2.points
  2. team2.points - team1.points
  3. team1 > team2
  4. team2 < team1
Q3MCQ3 marks
question figure question figure
Text of the picture (copyable)
Consider the following Vue application with javascript file "app.js" and markup file "index.html".

index.html:
```html
<body>
    <div id="app"></div>
</body>
```

app.js:
```javascript
const Category = {
    template:
        `<div>{{$route.params.name}}<router-view></router-view></div>`,
}

const Error = {
    template: `<div><slot> Page Not Found </slot></div>`,
}

const Product = {
    template: `
<div>
    <div v-if='filteredProducts.length > 0'>
        <div v-for='product in filteredProducts'>
            Name: {{product.name}}, Price: {{product.price}}
        </div>
    </div>
    <Error v-else> No {{keyword}} Found </Error>
</div>`,
    data() {
        return {
            keyword: this.$route.params.name,
            products: [
                { category: 'Mobile', name: 'Samsung', price: '10K' },
```
```javascript
{
  category: 'Mobile',
  name: 'Apple',
  price: '50K'
}, {
  category: 'Laptop',
  name: 'Lenovo',
  price: '70K'
}, ],
},
computed: {
  filteredProducts() {
    return this.products.filter(
      (product) =>
      product.category.toLowerCase() ==
      this.keyword.toLowerCase()
    )
  },
},
components: {
  Error,
},
}
const router = new VueRouter({
  routes: [{
    path: '/category/:name',
    component: Category,
    children: [{
      path: 'product',
      component: Product
    }],
  }, {
    path: '*',
    component: Error
  }, ],
})

new Vue({
  el: '#app',
  template: '<div><router-view /></div>',
  router,
})
```
Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the URL "http://localhost:8080/#/"?
  1. question figure
    text
    Page Not Found
  2. question figure
    text
    laptop
    Name: Lenovo, Price: 70K
  3. question figure
    text
    desktop
    No desktop Found
  4. question figure
    text
    mobile
    Name: Samsung, Price: 10K
    Name: Apple, Price: 50K
Q4MCQ3 marks
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Text of the picture (copyable)
index.html:
```html
<body>
    <div id="app"></div>
</body>
```

app.js:
```javascript
const Category = {
    template:
        `<div>{{ $route.params.name }}<router-view></router-view></div>`,
}

const Error = {
    template: `<div><slot> Page Not Found </slot></div>`,
}

const Product = {
    template: `
    <div>
        <div v-if='filteredProducts.length > 0'>
            <div v-for='product in filteredProducts'>
                Name: {{ product.name }}, Price: {{ product.price }}
            </div>
        </div>
        <Error v-else> No {{keyword}} Found </Error>
    </div>`,
    data() {
        return {
            keyword: this.$route.params.name,
            products: [
                { category: 'Mobile', name: 'Samsung', price: '10K' },
                { category: 'Mobile', name: 'Apple', price: '50K' },
                { category: 'Laptop', name: 'Lenovo', price: '70K' },
            ],
        }
    },
```
```javascript
computed: {
  filteredProducts () {
    return this.products.filter(
      (product) =>
        product.category.toLowerCase() ==
        this.keyword.toLowerCase()
    )
  },
},
components: {
  Error,
},

const router = new VueRouter({
  routes: [
    {
      path: '/category/:name',
      component: Category,
      children: [{ path: 'product', component: Product }],
    },
    { path: '*', component: Error },
  ],
})

new Vue({
  el: '#app',
  template: '<div><router-view /></router-view></div>',
  router,
})
```
Suppose the application is running on “http://localhost:8080”. What will be rendered by the browser for the URL “http://localhost:8080/#/category/desktop/product”?
  1. question figure
    text
    Page Not Found
  2. question figure
    text
    laptop
    Name: Lenovo, Price: 70K
  3. question figure
    text
    desktop
    No desktop Found
  4. question figure
    text
    mobile
    Name: Samsung, Price: 10K
    Name: Apple, Price: 50K
Q5MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with javascript file "app.js" and markup file "index.html".

index.html
```html
<body>
    <div id="app"></div>
</body>
```

app.js
```javascript
const Product = {
    template: `<div>
        <slot name="title">No title</slot>
        <slot>No Description Given</slot>
        <slot name="price">Flexible</slot>
    </div>`,
}

new Vue({
    el: '#app',
    template: `
        <Product>
            <p>
                <b>Lenovo Desktop</b>
                8GB RAM, 512GB SSD
            </p>
            <template v-slot:price>
                61K
            </template>
        </Product>`,
    components: {
        Product,
    },
})
```

Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the URL "http://localhost:8080/#/"?
  1. question figure
    text
    No title
    **Lenovo Desktop** 8GB RAM, 512GB SSD
    61K
  2. question figure
    text
    Lenovo Desktop
    8GB RAM, 512GB SSD
    61K
  3. question figure
    text
    Lenovo Desktop
    8GB RAM, 512GB SSD
    Flexible
  4. question figure
    text
    No title
    **Lenovo Desktop** 8GB RAM, 512GB SSD
    Flexible
Q6MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program, and predict the output, if executed.

```javascript
const data = {
  count: 10
};

const newData = {}

Object.defineProperty(newData, 'count', {
  get() {
    return data.count;
  },
  set(newValue) {
    data.count = newValue;
  },
});
console.log("Before Update:", newData.count);
newData.count = 20;
console.log("After Update:", data.count);
```
  1. Before Update: 10After Update: 10
  2. Before Update: 10Error
  3. Before Update: 10After Update: 20
  4. Before Update: 10After Update: undefined
Q7MCQ2 marks
Which of the following is correct regarding the finally block of Promise?
  1. It allows scheduling a function after the promise is rejected.
  2. It allows scheduling a function after the promise is resolved.
  3. It allows scheduling a function when promise is either fulfilled or rejected.
  4. None of these
Q8MCQ2 marks
Which of the following statements is true?
  1. The data stored in session storage gets lost as soon as the page is refreshed.
  2. The data stored in local storage gets lost as soon as the system shuts down.
  3. The data stored in session cookies gets lost as soon as the browser is closed.
  4. All of these
Q9MCQ4.5 marks
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Text of the picture (copyable)
```javascript
const Teams = {
  template: `<ol><li v-for='team in
  teams'>{{team.name}}</li></ol>`,
  data() {
    return {
      teams: [
        { name: 'India', points: 827 },
        { name: 'Australia', points: 820 },
      ],
    }
  },
}

const Rankings = {
  template: `<ol><li v-for='team in sortedTeams'>
  {{team.name}}</li></ol>`,
  data() {
    return Teams.data()
  },
  computed: {
    sortedTeams() {
      return this.teams.sort((team1, team2) => {
        return team1.points - team2.points // Statement 1
      })
    },
  },
}

const router = new VueRouter({
  routes: [
    { path: '/', component: Teams },
    { path: '/ranking', component: Rankings },
  ],
})

new Vue({
  el: '#app',
  template: `<div> <router-view /> </div>`,
  router,
})
```

index.html:
```html
<div id="app"></div>
```

Suppose the application is running on "http://localhost:8080". What will be rendered by the browser for the url "http://localhost:8080/#/ranking"
  1. question figure
    text
    Australia
  2. question figure
    text
    India
  3. question figure
    text
    1. Australia
    2. India
  4. question figure
    text
    1. India
    2. Australia
Q10MCQ4.5 marks
Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”. question figure Consider the following Vue application with javascript file “app.js” and markup file “index.html”.
Text of the picture (copyable)
index.html:
```html
<body>
    <div id="app"></div>
</body>
```

app.js:
```javascript
const Category = {
    template:
        `<div>{{ $route.params.name }}<router-view></router-view></div>`,
}

const Error = {
    template: `<div><slot> Page Not Found </slot></div>`,
}

const Product = {
    template: `
        <div>
            <div v-if='filteredProducts.length > 0'>
                <div v-for='product in filteredProducts'>
                    Name: {{ product.name }}, Price: {{ product.price }}
                </div>
            </div>
            <Error v-else> No {{keyword}} Found </Error>
        </div>`,
    data() {
        return {
            keyword: this.$route.params.name,
            products: [
                { category: 'Mobile', name: 'Samsung', price: '10K' },
                { category: 'Mobile', name: 'Apple', price: '50K' },
                { category: 'Laptop', name: 'Lenovo', price: '70K' },
            ],
        }
    },
```
```javascript
computed: {
  filteredProducts() {
    return this.products.filter(
      (product) =>
      product.category.toLowerCase() ==
      this.keyword.toLowerCase()
    )
  },
},
components: {
  Error,
},

const router = new VueRouter({
  routes: [{
    path: '/category/:name',
    component: Category,
    children: [{
      path: 'product',
      component: Product
    }],
  }, {
    path: '*',
    component: Error
  }, ],
})

new Vue({
  el: '#app',
  template: '<div><router-view /></div > ',
  router,
})
```
Suppose the application is running on “http://localhost:8080”. What will be rendered by the browser for the URL “http://localhost:8080/#/category/mobile/product”?
  1. question figure
    text
    Page Not Found
  2. question figure
    text
    laptop
    Name: Lenovo, Price: 70K
  3. question figure
    text
    desktop
    No desktop Found
  4. question figure
    text
    mobile
    Name: Samsung, Price: 10K
    Name: Apple, Price: 50K
Q11MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below javascript program, and predict the output, if executed.

```javascript
let x = 50;

const obj1 = {
  x: 10,
  func: function(x) {
    console.log(x, "and", this.x)
  }
}

const obj2 = {
  x: 20,
  func: function() {
    console.log(x, "and", this.x)
    obj1.func.call(this)
  }
}

obj2.func.call(obj1)
```
  1. 50 and 10undefined and 20
  2. 50 and 10undefined and 10
  3. 50 and 2050 and 20
  4. 20 and 1050 and 10
Q12MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
async function result (x) {
  const y = 6;
  return new Promise (((reject, resolve) => {
    if ((((x * 28) / (7 * x) - 2) == 1))
      reject(y ** 2)
    console.log("Inside Promise")
    resolve(y ** 3)
  }))
}

result(x).then(
  rej => console.log("Promise rejected with the value", rej),
  res => console.log("Promise resolved with the value", res)
).then(data => {
  console.log("Data received is", data);
  return "6"
}).finally(data => {
  console.log("Data received is", data);
  return "34"
}).then(data => console.log("Data received is", data))
```

Assuming the variable "x" passed to the "result" function is a whole number between 1 and 99 (including 1 and 99), what will be shown on the console, if the above program is executed?
  1. Promise resolved with the value 36Data received is 36Data received is 6Data received is 34
  2. Inside PromisePromise rejected with the value 36Data received is undefinedData received is undefinedData received is 34
  3. Promise rejected with the value 216Data received is undefinedData received is undefinedData received is 34
  4. Inside PromisePromise rejected with the value 216Data received is undefinedData received is undefinedData received is 6
Q13MSQ3 marksselect all that apply
Which of the following statement(s) is/are true regarding javascript?
  1. The “this” reference always refers to the global object inside an arrow function.
  2. The “call” and “apply” functions are the same, if the calling function doesn’taccept any arguments.
  3. A variable, declared using “var” outside any function, is accessible throughoutthe program.
  4. All of these
Q14MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Which of the following statement(s) is/are true regarding JavaScript language?
```javascript
function rule (num, obj) {
  // some code here
}
rule(num, obj);
```
  1. In the above function call, the variable “num” is passed by value, assuming it tobe holding a string literal.
  2. In the above function call, the variable “obj” is passed by reference, assuming itto be holding an object.
  3. A variable declared using the keyword “var” will have the value “null”, until it isinitialized.
  4. All of these
Q15MSQ2 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the below Vue class bindings:
Code 1:

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

Code 2:

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

Which of the following statement(s) is/are true?
  1. Both the code snippets will render the same HTML.
  2. Both the code snippets will render the different HTML.
  3. The code snippet 2 will always render the element div with class “activeClass”,and “errorClass” will only be applied, if the data variable “isActive” is truthy.
  4. The code snippet 1 will always render the element div with class “errorClass”,and “activeClass” will only be applied”, if the data variable “isActive” is truthy.
Q16MSQ2 marksselect all that apply
Which of the following statement(s) is/are correct in the context of REST and GraphQL?
  1. Both REST and GraphQL are software architectural styles.
  2. Both REST and GraphQL are in general used for fetching data from a remotestorage.
  3. Every API must adhere to all the REST principles.
  4. In GraphQL, a write operation should be performed explicitly via a mutation, ingeneral.

Answer key

  1. Q1 (MCQ, 3 marks): C
  2. Q2 (MCQ, 3 marks): B
  3. Q3 (MCQ, 3 marks): A
  4. Q4 (MCQ, 3 marks): C
  5. Q5 (MCQ, 3 marks): A
  6. Q6 (MCQ, 3 marks): C
  7. Q7 (MCQ, 2 marks): C
  8. Q8 (MCQ, 2 marks): C
  9. Q9 (MCQ, 4.5 marks): C
  10. Q10 (MCQ, 4.5 marks): D
  11. Q11 (MCQ, 4.5 marks): B
  12. Q12 (MCQ, 4.5 marks): D
  13. Q13 (MSQ, 3 marks): B, C
  14. Q14 (MSQ, 3 marks): A, B
  15. Q15 (MSQ, 2 marks): A, D
  16. Q16 (MSQ, 2 marks): B, D