MAD Study Hub

Home / Past papers / MAD2 Quiz 1 / this paper

2024 July07: IIT M AN EXAM QDD2 - 07 Jul 2024

MAD2 Quiz 116 questions50 marks15 MCQ · 1 MSQafternoon / QDD2
Elapsed 00:00
Q1MCQ2 marks
question figure
Text of the picture (copyable)
Which of the following methods is not a valid DOM method in JavaScript?
  1. question figure
    text
    ```
    getElementById()
    ```
  2. question figure
    text
    ```
    getElementByPropertyName()
    ```
  3. question figure
    text
    ```
    getElementsByTagName()
    ```
  4. question figure
    text
    ```
    getElementByClassName()
    ```
Q2MCQ2 marks
question figure
Text of the picture (copyable)
What will be the output of the following code snippet?

```javascript
let result = "";
for (let i = 0; i < 3; i++) {
  for (let j = 0; j < 2; j++) {
    result += "" + i + j + "";
  }
}
console.log(result);
```
  1. question figure
    text
    0 1 1 2 2 3
  2. question figure
    text
    0 1 1 2 2 3 3 4
  3. question figure
    text
    0 1 2 3 4 5
  4. question figure
    text
    00 01 10 11 20 21
Q3MCQ2 marks
Which of the following statements best describes the ephemeral state?
  1. Data that persists across browser sessions.
  2. Data that is stored in a server-side database.
  3. Temporary data that is not preserved across re-renders.
  4. Data that is cached in the client's browser.
Q4MCQ2 marks
What is the difference between v-bind and v-model directives in Vue.js?
  1. “v-bind” is used for one-way data binding, while “v-model” is used for two-waydata binding.
  2. “v-bind” is used for two-way data binding, while “v-model” is used for one-waydata binding.
  3. Both “v-bind” and “v-model” are used for one-way data binding.
  4. Both “v-bind” and “v-model” are used for two-way data binding.
Q5MCQ3 marks
question figure
Text of the picture (copyable)
What will be the output of the following JavaScript code?

```javascript
let x = undefined;
let y = null;
let z = NaN;
console.log(x == y, x === y, y == z, y === z, isNaN(z));
```
  1. question figure
    text
    true false false true false
  2. question figure
    text
    false false false false true
  3. question figure
    text
    true false false false true
  4. question figure
    text
    false true true false false
Q6MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const a = 15;

const obj1 = {
    a: 20,
    b: function () {
        console.log(this.a);
        this.b();
    }
}

const obj2 = {
    a: 10,
    b: () => {
        console.log(this.a);
    }
}

obj1.b.apply(obj2);
```

What will be the output of the above program, if executed?
  1. question figure
    text
    20
    20
  2. question figure
    text
    20
    undefined
  3. question figure
    text
    undefined
    undefined
  4. question figure
    text
    10
    undefined
  5. question figure
    text
    The program will crash due to maximum call stack size exceeded error.
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
let users = [
  { name: "Alice", age: 25 },
  { name: "Bob", age: 22 },
  { name: "Charlie", age: 30 },
];
users.sort((a, b) => a.age - b.age);
console.log(users.map((user) => user.name).join(", "));
```

What will be the output when the code is executed?
  1. question figure
    text
    Alice, Bob, Charlie
  2. question figure
    text
    Bob, Alice, Charlie
  3. question figure
    text
    Charlie, Alice, Bob
  4. question figure
    text
    Charlie, Bob, Alice
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
const words = ['apple', 'banana', 'orange', 'grape', 'kiwi'];
const result = words.map(word => word.length).filter(len => len > 5);
console.log(result);
```

What will be the output of the above program, if executed?
  1. question figure
    text
    ```
    ['apple', 'banana', 'orange', 'grape', 'kiwi']
    ```
  2. question figure
    text
    ```
    [5, 6, 6, 5, 4]
    ```
  3. question figure
    text
    ```
    ['banana', 'orange']
    ```
  4. question figure
    text
    [6, 6]
  5. question figure
    text
    [5, 5]
  6. question figure
    text
    ```
    [true, true]
    ```
Q9MCQ3 marks
What is state management in the context of a web application?
  1. Organizing and storing data on the server-side database.
  2. Handling and updating the state of client-side components and data.
  3. Managing user session data using browser cookies.
  4. Coordinating the state of HTTP requests and responses between client andserver.
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript program.

```javascript
const obj1={
    age: 29,
    toy: 'kite'
}

const obj2={
    __proto__: obj1,
    animal: 'dogs',
    members: 45
}

console.log(obj1.toy)
console.log(obj1.animal)
console.log(obj2.age)
console.log(obj2.members)
console.log(Object.keys(obj2))
```
What will be the output of the above program, if executed?
  1. question figure
    text
    ```
    kite
    undefined
    29
    45
    ['animal', 'members', 'age', 'toy']
    ```
  2. question figure
    text
    ```
    kite
    dogs
    undefined
    45
    ['age', 'toy', 'animal', 'members']
    ```
  3. question figure
    text
    ```
    kite
    dogs
    undefined
    45
    ['age', 'toy']
    ```
  4. question figure
    text
    ```
    kite
    undefined
    29
    45
    ['animal', 'members']
    ```
Q11MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following html.

```html
<div id="app">
    <p>{{ message }}</p>
    <button @click="updateMessage">Click me</button>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            message: 'Hello!'
        },
        methods: {
            updateMessage() {
                this.message += '!';
            }
        }
    });
</script>
```

Assuming vue cdn has been added to the html and the html format is correct. What would be the output on the screen after clicking the button twice?
  1. question figure
    text
    Hello
  2. question figure
    text
    Hello!
  3. question figure
    text
    Hello!!
  4. question figure
    text
    Hello!!!
Q12MSQ3 marksselect all that apply
Which of the following is/are correct definition(s) of an arrow function that accepts a number and returns its square?
  1. question figure
    text
    ```javascript
    let func = (num) => return num1*num1;
    ```
  2. question figure
    text
    ```javascript
    let func = (num) => { num1*num1; }
    ```
  3. question figure
    text
    ```javascript
    let func = (num) => num1*num1;
    ```
  4. question figure
    text
    ```javascript
    let func = (num) => { return num1*num1; }
    ```
Q13MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code embedded in the body of the HTML document given below.

```html
<html>
<body>
    <div id="mybox">Test JS</div>
    <script>
        let count = 0;
        let change = setInterval(()=>{
            let box = document.getElementById('mybox');
            if(count % 2 == 1){
                box.style.backgroundColor = 'red';
                count++;
            }
            else if(count % 3 == 1){
                box.style.backgroundColor = 'green';
                count++;
            }
            else{
                box.style.backgroundColor = 'yellow';
                count++;
            }
        }, 1000)
    </script>
</body>
</html>
```

If the document is rendered on the browser, what will be the sequence of background colors taken by the element with id="mybox" in the first 6 seconds of execution?
  1. question figure
    text
    Red → Green → Yellow → Red → Green → Yellow
  2. question figure
    text
    Red → Green → Red → Yellow → Red → Yellow
  3. question figure
    text
    Yellow → Green → Yellow → Green → Yellow → Green
  4. question figure
    text
    Yellow → Red → Yellow → Red → Green → Red
Q14MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
class Region{
    constructor(region){
        this.region = region;
    }
    get describe(){
        return `${this.region} is one of the major geographical regions.`
    }
}

class Country extends Region {
    constructor(region, country, nation){
        super(region)
        this.country = country;
        this.nation = nation;
    }
    get describe(){
        return `${this.country} is a ${this.nation} nation in the region of ${this.region}.`
    }
}

let Australia = new Region('Australia and NZ', 'Australia', 'developed')
let Germany = new Country('Europe', 'Germany', 'developed')
console.log(Australia.describe)
console.log(Germany.describe)
```

What will be the output of the above program, if executed?
  1. question figure
    text
    ```
    Australia is a developed nation in the region of Australia and NZ.
    Germany is a developed nation in the region of Europe.
    ```
  2. question figure
    text
    Australia and NZ is one of the major geographical regions.
    Germany is one of the major geographical regions.
  3. question figure
    text
    ```
    Australia is a developed nation in the region of Australia and NZ.
    Germany is one of the major geographical regions.
    ```
  4. question figure
    text
    Australia and NZ is one of the major geographical regions.
    Germany is a developed nation in the region of Europe.
Q15MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup index.html and JavaScript file app.js.
File: index.html

```html
<div id = "app">
    <div>Welcome to Frontend Development</div>
    <new>Vue is a Frontend Framework</new>
</div>
<script src="script.js"></script>
```

File: script.js

```javascript
Vue.component('new', {
    template : `<div>
        <slot>Vue is JS Framework</slot>
        <div>Learn Vue 2 and Vue 3</div>
    </div>`
});

new Vue({
    el : "#app",
})
```

What will be rendered on the browser screen?
  1. question figure
    text
    Welcome to Frontend Development
    Vue is a JS Framework
    Vue is a Frontend Framework
    Learn Vue 2 and Vue 3
  2. question figure
    text
    Welcome to Frontend Development
    Vue is a Frontend Framework
    Vue is a JS Framework
    Learn Vue 2 and Vue 3
  3. question figure
    text
    Welcome to Frontend Development
    Vue is a Frontend Framework
    Learn Vue 2 and Vue 3
  4. question figure
    text
    Welcome to Frontend Development
    Vue is a JS Framework
    Learn Vue 2 and Vue 3
Q16MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following html.

```html
<div id="app">
    <parent-component :title="parentTitle">
        <template slot="header">
            <h2>{{ headerTitle }}</h2>
        </template>
    </parent-component>
</div>

<script>
Vue.component('parent-component', {
    props: ['title'],
    template: `
        <div>
            <h1>{{ title }}</h1>
            <slot name="header"></slot>
            <p>Main Content</p>
        </div>
    `
});

new Vue({
    el: '#app',
    data: {
        parentTitle: 'Parent Component Title',
        headerTitle: 'Header Content'
    }
});
</script>
```

Assuming Vue CDN has been added to the HTML and the HTML format is correct.
What would be the output on the screen?
  1. question figure
    text
    Parent Component Title
    Main Content
  2. question figure
    text
    Parent Component Title
    Header Content
    Main Content
  3. question figure
    text
    Parent Component Title
    ```html
    <h2>{{ headerTitle }}</h2>
    ```
    Main Content
  4. question figure
    text
    Header Content
    Main Content

Answer key

  1. Q1 (MCQ, 2 marks): B
  2. Q2 (MCQ, 2 marks): D
  3. Q3 (MCQ, 2 marks): C
  4. Q4 (MCQ, 2 marks): A
  5. Q5 (MCQ, 3 marks): C
  6. Q6 (MCQ, 3 marks): D
  7. Q7 (MCQ, 3 marks): B
  8. Q8 (MCQ, 3 marks): D
  9. Q9 (MCQ, 3 marks): B
  10. Q10 (MCQ, 3 marks): D
  11. Q11 (MCQ, 3 marks): D
  12. Q12 (MSQ, 3 marks): C, D
  13. Q13 (MCQ, 4.5 marks): D
  14. Q14 (MCQ, 4.5 marks): D
  15. Q15 (MCQ, 4.5 marks): C
  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 and Concepts

JavaScript and DOM Manipulation

  1. DOM Methods:

    • getElementById()
    • getElementsByTagName()
    • getElementsByClassName()
    • getElementByPropertyName() (Not a valid DOM method)
  1. Loops and Concatenation:

    • Understanding nested loops and string concatenation.
    • Example:

      let result = "";
      for (let i = 0; i < 3; i++) {
          for (let j = 0; j < 2; j++) {
              result += " " + i + j + " ";
          }
      }
      console.log(result); // Output: " 00 01 10 11 20 21"
  1. Ephemeral State:

    • Temporary data that is not preserved across re-renders.
  1. JavaScript Comparisons and NaN:

    • Understanding undefined, null, and NaN.
    • Example:

      let x = undefined;
      let y = null;
      let z = NaN;
      console.log(x === y, x === y, y === z, y === z, isNaN(z)); // Output: false, false, false, false, true
  1. Arrow Functions and this Context:

    • Understanding the behavior of this in arrow functions vs. regular functions.
    • Example:

      const obj1 = {
        a: 20,
        b: function() {
          console.log(this.a);
        }
      };
      const obj2 = {
        a: 10,
        b: () => {
          console.log(this.a);
        }
      };
      obj1.b.apply(obj2); // Output: 10, undefined
  1. Array Methods:

    • map, filter, and sort methods.
    • Example:

      let users = [
          { name: "Alice", age: 25 },
          { name: "Bob", age: 22 },
          { name: "Charlie", age: 30 },
      ];
      users.sort((a, b) => a.age - b.age);
      console.log(users.map((user) => user.name).join(", ")); // Output: "Bob, Alice, Charlie"

Vue.js

  1. State Management:

    • Handling and updating the state of client-side components and data.
  1. Directives:

    • v-bind: One-way data binding.
    • v-model: Two-way data binding.
  1. Vue Components and Slots:

    • Understanding Vue components, props, and slots.
    • Example:

      <div id="app">
        <parent-component :title="parentTitle">
          <template slot="header">
            <h2>{{ headerTitle }}</h2>
          </template>
        </parent-component>
      </div>
      Vue.component('parent-component', {
        props: ['title'],
        template: `
          <div>
            <h1>{{ title }}</h1>
            <slot name="header"></slot>
            <p>Main Content</p>
          </div>
        `
      });
      new Vue({
        el: '#app',
        data: {
          parentTitle: 'Parent Component Title',
          headerTitle: 'Header Content'
        }
      });

Object-Oriented Programming in JavaScript

  1. Prototypes and Inheritance:

    • Understanding __proto__ and inheritance.
    • Example:

      const obj1 = {
        age: 29,
        toy: 'kite'
      };
      const obj2 = {
        __proto__: obj1,
        animal: 'dogs',
        members: 45
      };
      console.log(obj1.toy); // Output: 'kite'
      console.log(obj1.animal); // Output: undefined
      console.log(obj2.age); // Output: 29
      console.log(obj2.members); // Output: 45
      console.log(Object.keys(obj2)); // Output: ['animal', 'members']
  1. Classes and Inheritance:

    • Understanding class definitions and inheritance.
    • Example:

      class Region {
          constructor(region) {
              this.region = region;
          }
          get describe() {
              return `${this.region} is one of the major geographical regions.`;
          }
      }
      class Country extends Region {
          constructor(region, country, nation) {
              super(region);
              this.country = country;
              this.nation = nation;
          }
          get describe() {
              return `${this.country} is a ${this.nation} nation in the region of ${this.region}.`;
          }
      }
      let Australia = new Region('Australia and NZ');
      let Germany = new Country('Europe', 'Germany', 'developed');
      console.log(Australia.describe); // Output: 'Australia and NZ is one of the major geographical regions.'
      console.log(Germany.describe); // Output: 'Germany is a developed nation in the region of Europe.'