MAD Study Hub

Home / Past papers / MAD2 Quiz 2 / this paper

IIT M DIPLOMA AN EXAM QDD3 16 Mar - 16 Mar 2025

MAD2 Quiz 216 questions50 marks16 MCQDiploma / afternoon / QDD3
Elapsed 00:00
Q1MCQ2 marks
question figure
Text of the picture (copyable)
In Vue.js reactivity system, when is a computed property re-evaluated?
  1. On every component render
  2. When one of its reactive dependencies changes
  3. At fixed time intervals
  4. Only when explicitly called
Q2MCQ2 marks
question figure
Text of the picture (copyable)
What is the correct way to implement two-way data binding in a custom component
in Vue.js 2?
  1. Use v-bind directly with a prop
  2. Create a computed property with getter and setter
  3. Use v-model with corresponding prop and emit
  4. Modify the prop value directly in the child component
Q3MCQ2 marks
question figure
Text of the picture (copyable)
What distinguishes a Progressive Web App (PWA) from a traditional web application?
  1. PWAs must be downloaded from an app store
  2. PWAs only work on mobile devices
  3. PWAs can work offline and be installed on the home screen
  4. PWAs require native mobile code
Q4MCQ2 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
function testScope() {
  if (true) {
    var x = 10;
    let y = 20;
  }
  console.log(x);
  console.log(y);
}
testScope();
```

What will be the output of the above program?
  1. question figure
    text
    10
    undefined
  2. question figure
    text
    undefined
    10
  3. question figure
    text
    10
    Error
  4. question figure
    text
    Error
Q5MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
let count = 0;

async function increment() {
  const incrementCount = () => {
    return new Promise(resolve => {
      setTimeout(() => {
        count++;
        resolve(count);
      }, 100);
    });
  };

  const results = await Promise.all([incrementCount(), incrementCount(), incrementCount()]);
  console.log(results);
}

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

What will be the output of the above program?
  1. question figure
    text
    [1, 1, 1]
    Start
  2. question figure
    text
    Start
    [1, 1, 1]
  3. question figure
    text
    [1, 2, 3]
    Start
  4. question figure
    text
    Start
    [1, 2, 3]
Q6MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
const obj = { a: 1, b: 2 };
const { a, ...rest } = obj;
console.log(a, rest);
```

What will be the output of the above program?
  1. Error
  2. { a: 1, b: 2 } undefined
  3. { a: 1, b: 2 } { a: 1, b: 2 }
  4. 1 undefined
  5. 1 { b: 2 }
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vue router setup.

```javascript
const Product = {
  template: `<div><h1>Product {{ $route.params.id }}</h1></div>`
};

const ProductReviews = {
  template: `<div><h2>Reviews for Product</h2></div>`
};

const routes = [
  {
    path: '/products/:id',
    component: Product,
    children: [
      {
        path: 'reviews',
        component: ProductReviews
      }
    ]
  }
];

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

What will be the behavior when the user visits "/products/123/reviews"?
  1. The Product component will be displayed with the id 123, and theProductReviews component will be displayed as a child route.
  2. The Product component will not display anything because the reviews path isincorrectly nested.
  3. Only the ProductReviews component will be displayed, and the Productcomponent will be ignored.
  4. A 404 error will be shown because the /reviews route cannot be accessed as achild route.
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below Vuex setup.

```javascript
const store = new Vuex.Store({
  state: {
    cart: [
      { id: 1, name: 'Item 1', price: 100 },
      { id: 2, name: 'Item 2', price: 200 }
    ]
  },
  getters: {
    totalPrice(state) {
      return state.cart.reduce((total, item) => total + item.price, 0);
    }
  },
  mutations: {
    addToCart(state, item) {
      state.cart.push(item);
    }
  },
  actions: {
    addItemToCart({ commit }, item) {
      commit('addToCart', item);
    }
  }
});
```

What will happen if the user dispatches the "addItemToCart" action to add a new item to the cart?
  1. The total price will remain the same until the page is refreshed.
  2. The total price will not reflect the new item because the getter is not reactive.
  3. The total price will be updated immediately in the Vuex store.
  4. A mutation error will occur because the cart array is not updated.
Q9MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following javascript code.

```javascript
async function fetchData() {
  try {
    const response = await fetch('https://api.example.com/data');
    if (!response.ok) throw new Error('HTTP error');
    const data = await response.json();
    return data;
  } catch (error) {
    if (error.name === 'TypeError') {
      return { status: 'network error' };
    }
    return { status: 'http error' };
  }
}
```

When the function is called what will be returned if the server is **unreachable**?
  1. { status: 'http error' }
  2. { status: 'network error' }
  3. undefined
  4. The promise will remain pending
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following javascript code.

```javascript
function translateToEmoji(msg, dictionary, cb) {
  const translated = msg
    .split(' ')
    .map(word => dictionary[word] || word);
  cb(translated.join(' '));
}

translateToEmoji('i love code',
  { heart: '❤️', code: '💻' },
  result => console.log(result));
```

What's logged?
  1. question figure
    text
    "i love code"
  2. question figure
    text
    "I ❤️ 💻"
  3. question figure
    text
    "undefined undefined undefined"
  4. question figure
    text
    "i love 💻"
Q11MCQ3 marks
If a user clicks rapidly twice (within 500ms), what will the likes count be? question figure
Text of the picture (copyable)
Consider the following html with relevant vue cdn links added.

```html
<div id="app">
    <button @click="addLike">Like</button>
    <div>{{likes}}</div>
</div>
<script>
    new Vue({
        el: '#app',
        data: () => ({
            likes: 0,
            lastClick: 0
        }),
        methods: {
            addLike() {
                if (Date.now() - this.lastClick < 500) {
                    this.likes += 2;
                } else {
                    this.likes += 1;
                }
                this.lastClick = Date.now();
            }
        }
    })
</script>
```
  1. 1
  2. 2
  3. 3
  4. 4
Q12MCQ3 marks
In the Vue application above, what will be the initial rendered message? question figure
Text of the picture (copyable)
Consider the following html with relevant vue cdn links added.
```html
<div id="app">
    <async-component ref="child"></async-component>
    <button @click="updateParent">Update Parent</button>
</div>

<script>
    Vue.component('async-component', {
        template: '<div>{{message}}</div>',
        data() {
            return {
                message: 'Initial'
            }
        },
        mounted() {
            setTimeout(() => {
                this.message = 'Updated in child'
            }, 0)
        }
    })

    new Vue({
        el: '#app',
        mounted() {
            this.$refs.child.message = 'Updated in parent'
        },
        methods: {
            updateParent() {
                this.$refs.child.message = 'Button clicked'
            }
        }
    })
</script>
```
  1. "Initial"
  2. "Updated in parent"
  3. "Updated in child"
  4. "Button clicked"
Q13MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
const promiseChain = new Promise((resolve, reject) => {
  console.log('Step 1');
  resolve(1);
})
  .then((value) => {
    console.log('Step 2:', value);
    return value + 1;
  })
  .then((value) => {
    console.log('Step 3:', value);
    throw new Error('Error in Step 3');
  })
  .then((value) => {
    console.log('Step 4:', value);
    return value * 2;
  })
  .catch((err) => {
    console.log('Caught:', err.message);
    return 5;
  })
  .then((value) => {
    console.log('Step 5:', value);
    return value + 1;
  });

console.log('End of Code');
```

What will be the output of the above program?
  1. Step 1Step 2: 1 Step 3: 2 Caught: Error in Step 3 End of Code
  2. Step 1Step 2: 1 Caught: Error in Step 3Step 5: 5 End of Code
  3. Step 1Step 2: 1 Step 3: 2 End of Code
  4. Step 1End of Code Step 2: 1 Step 3: 2 Caught: Error in Step 3 Step 5: 5
Q14MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below Vue router setup.

Note: Assume that the API "/api/users/userId" is operational and returns the user's data including name.

```javascript
const UserProfile = {
  template: `<div><h2>User Profile</h2><p>{{ user.name }}</p></div>`,
  data() {
    return {
      user: {}
    };
  },
  created() {
    this.fetchUserData();
  },
  methods: {
    async fetchUserData() {
      const userId = this.$route.query.userId;
      const response = await fetch(`/api/users/${userId}`);
      this.user = await response.json();
    }
  }
};

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

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

What will happen if the user navigates to "/user?userId=123"?
  1. The component will display the user's name (fetched from API) correctly asexpected.
  2. The component will show because the API call will never be triggered.
  3. The component will always show an empty profile because the userId queryparameter is not reactive.
  4. The component will throw an error because this.$route.query is not defined.
Q15MCQ4.5 marks
What will be the visited pages history when the user navigates between pages and refreshes the page? question figure
Text of the picture (copyable)
Consider the below Vue.js application.

```html
<template>
  <div>
    <button @click="goToPage('Home')">Go to Home</button>
    <button @click="goToPage('About')">Go to About</button>
    <button @click="goToPage('Contact')">Go to Contact</button>

    <div v-if="visitedPages.length">
      <h3>Visited Pages:</h3>
      <ul>
        <li v-for="(page, index) in visitedPages" :key="index">{{ page }}</li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      visitedPages: []
    };
  },
  mounted() {
    const storedPages = JSON.parse(sessionStorage.getItem('visitedPages')) || [];
    this.visitedPages = storedPages;
  },
  methods: {
    goToPage(page) {
      this.visitedPages.push(page);
      sessionStorage.setItem('visitedPages',
        JSON.stringify(this.visitedPages));
      this.$router.push(`/${page.toLowerCase()}`);
    }
  }
};
</script>
```
  1. The list of visited pages will reset to empty after the page is refreshed.
  2. The list of visited pages will be updated with the current page after everynavigation and will not reset even after reload.
  3. The navigation history will not be stored in sessionStorage.
  4. All of these
Q16MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below Vue.js application.

```html
<template>
  <div>
    <input v-model="name" placeholder="Enter name">
    <input v-model="email" placeholder="Enter email">
    <button @click="submitForm">Submit</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      name: '',
      email: ''
    };
  },
  mounted() {
    if (localStorage.getItem('formData')) {
      const savedData = JSON.parse(localStorage.getItem('formData'));
      this.name = savedData.name;
      this.email = savedData.email;
    }
  },
  watch: {
    name(newVal) {
      localStorage.setItem('formData', JSON.stringify({ name: newVal, email: localStorage.email }));
    },
    email(newVal) {
      localStorage.setItem('formData', JSON.stringify({ name: localStorage.name, email: newVal }));
    }
  },
  methods: {
    submitForm() {
      localStorage.removeItem('formData');
      this.name = '';
      this.email = '';
    }
  }
};
</script>
```

What will happen if the user submits the form and reloads the page?
  1. The form data will persist in the input fields even after submission and pagereload.
  2. The form data will be cleared after submission, and no data will appear after apage reload.
  3. The form data will appear in the inputs after submission and page reload, butonly until the user starts typing again.
  4. The page will go blank.

Answer key

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

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Summary of Core Topics, Concepts, Principles, and Equations

Vue.js

  1. Reactivity System

    • Computed Properties: Re-evaluated when their reactive dependencies change.
    • Example: computed: { totalPrice() { return this.cart.reduce((total, item) => total + item.price, 0); } }
  1. Two-Way Data Binding

    • Using v-model with corresponding prop and emit.
    • Example:

      <template>
        <input :value="value" @input="$emit('input', $event.target.value)">
      </template>
      <script>
      export default {
        props: ['value']
      }
      </script>
  1. Vue Router

    • Nested Routes: Using children in route definitions.
    • Example:

      const routes = [
        {
          path: '/products/:id',
          component: Product,
          children: [
            {
              path: 'reviews',
              component: ProductReviews
            }
          ]
        }
      ];
  1. Vuex

    • State Management: Using state, getters, mutations, and actions.
    • Example:

      const store = new Vuex.Store({
        state: { count: 0 },
        mutations: {
          increment(state) {
            state.count++;
          }
        },
        actions: {
          increment({ commit }) {
            commit('increment');
          }
        }
      });

JavaScript

  1. Variable Scoping

    • var vs let: var has function scope, let has block scope.
    • Example:

      if (true) {
        var x = 10;
        let y = 20;
      }
      console.log(x); // 10
      console.log(y); // ReferenceError: y is not defined
  1. Asynchronous Programming

    • Promises and Async/Await: Handling asynchronous operations.
    • Example:

      async function fetchData() {
        const response = await fetch('https://api.example.com/data');
        const data = await response.json();
        return data;
      }
  1. Error Handling

    • Try/Catch Blocks: Handling errors in asynchronous code.
    • Example:

      try {
        const response = await fetch('https://api.example.com/data');
        if (!response.ok) throw new Error('HTTP error');
        const data = await response.json();
        return data;
      } catch (error) {
        console.error(error);
      }
  1. Destructuring Assignment

    • Extracting values from objects and arrays.
    • Example:

      const obj = { a: 1, b: 2 };
      const { a, ...rest } = obj;
      console.log(a, rest); // 1 { b: 2 }
  1. Promise Chaining

    • Chaining promises to handle asynchronous operations sequentially.
    • Example:

      new Promise((resolve, reject) => {
        resolve(1);
      })
      .then(value => {
        console.log(value);
        return value + 1;
      })
      .then(value => {
        console.log(value);
      });

Progressive Web Apps (PWAs)

  1. Offline Capabilities

    • Service Workers: Enabling offline functionality.
    • Example:

      if ('serviceWorker' in navigator) {
        navigator.serviceWorker.register('/sw.js');
      }
  1. Installation

    • Web App Manifest: Allowing installation on the home screen.
    • Example:

      {
        "name": "My PWA",
        "short_name": "PWA",
        "start_url": "/",
        "display": "standalone"
      }