MAD Study Hub

Home / Past papers / MAD2 Quiz 1 / this paper

IIT M DIPLOMA AN4 EXAM QDD4 25 Feb 2024 - 25 Feb 2024

MAD2 Quiz 116 questions50 marks13 MCQ · 3 MSQDiploma / QDD4
Elapsed 00:00
Q1MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
function checkThis() {
  return this.name
}

const Obj1 = {
  name: 'Obj1',
  checkThis: checkThis,
}

const Obj2 = {
  name: 'Obj2',
  checkThis: checkThis,
}

console.log(Obj2.checkThis(), Obj1.checkThis.call(Obj2))
```
  1. Obj1 Obj1
  2. Obj1 Obj2
  3. Obj2 Obj1
  4. Obj2 Obj2
Q2MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
const stateManager = function () {
  let defaultState = false
  function alterState() {
    defaultState = !defaultState
  }
  return {
    currentState() {
      return defaultState
    },
    changeState() {
      alterState()
    },
  }
}

const sm1 = stateManager()
sm1.changeState()
const sm2 = stateManager()

console.log(sm1.currentState(), sm2.currentState())
```
  1. true true
  2. true false
  3. false true
  4. false false
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
const player = {
  name: 'Rohit',
  state: 'Maharastra',
}

const batsman = Object.create(player)

console.log(batsman.name)
```
  1. question figure
    text
    Rohit
  2. question figure
    text
    undefined
  3. question figure
    text
    null
  4. question figure
    text
    None of these
Q4MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
const emails = [
    'user1@study.iitm.ac.in',
    'user2@gmail.com',
    'user3@study.iitm.ac.in',
]

const studentsEmail = emails.filter((email) =>
    email.endsWith('study.iitm.ac.in')
)
console.log(studentsEmail)
```
  1. question figure
    text
    [ user1@study.iitm.ac.in, user2@gmail.com, user3@study.iitm.ac.in ]
  2. question figure
    text
    [ user1@study.iitm.ac.in, user3@study.iitm.ac.in ]
  3. question figure
    text
    [ user2@gmail.com, user3@study.iitm.ac.in ]
  4. question figure
    text
    [user2@gmail.com]
Q5MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup index.html and JavaScript
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="./app.js"></script>
</body>
```

app.js
```javascript
new Vue({
    el: '#app',
    template: `
    <div>
        {{text}}
        <div>
            <input type="text" v-model="userInput" />
            <div id="match">
                {{hasMatched?"Not Matched":"Matched"}}
            </div>
        </div>
    </div>`,
    data: {
        text: 'This is text',
        userInput: null,
    },
    computed: {
        hasMatched() {
            return this.text.startsWith(this.userInput)
        },
    },
})
```

Suppose the application is running on "http://localhost:8080/". If the User inputs "This" in the input box. What will be rendered inside the div with id "match"?
  1. question figure
    text
    Not Matched
  2. question figure
    text
    Matched
  3. question figure
    text
    undefined
  4. question figure
    text
    null
Q6MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Vue application with markup index.html and JavaScript 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="./app.js"></script>
</body>
```

app.js
```javascript
new Vue({
    el: '#app',
    template: `<div>
        <div id="holiday">{{isHoliday?"Holiday":"Not Holiday"}}</div>
        <button @click="increaseCount">Increase Count</button>
    </div>`,
    data: {
        count: 1,
        isHoliday: false,
    },
    watch: {
        count() {
            if (this.count % 5 == 0) {
                this.isHoliday = true
            }
        },
    },
    methods: {
        increaseCount() {
            this.count += 6
        },
    },
})
```

Suppose the application is running on "http://localhost:8080" if the user clicks on button "Increase Count" 5 times. What will be rendered inside the div with id "holiday"?
  1. Holiday
  2. Not Holiday
  3. true
  4. false
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
class Album {
  constructor(creator, albumName) {
    this.creator = creator
    this.albumName = albumName
    this.songs = []
  }
  addSong(song) {
    this.songs.push(song)
  }
}

class Song {
  constructor(name, duration) {
    this.name = name
    this.duration = duration
    this.album = null
  }
  addAlbum(album) {
    this.album = album
  }
}

al = new Album('creator1', 'Album1')
s1 = new Song('Song1')

al.addSong(s1)
console.log(al.songs.length)
```
  1. 0
  2. 1
  3. 2
  4. None of these
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following JavaScript code. What will be logged on to the console once the code is executed?

```javascript
class Album {
  constructor(creator, albumName) {
    this.creator = creator
    this.albumName = albumName
    this.songs = []
  }
  addSong(song) {
    this.songs.push(song)
  }
}

class Song {
  constructor(name, duration) {
    this.name = name
    this.duration = duration
    this.album = null
  }
  addAlbum(album) {
    this.album = album
  }
}

al = new Album('creator1', 'Album1')
s1 = new Song('Song1')

s1.addAlbum(al)
console.log(al.songs.length)
```
  1. 0
  2. 1
  3. 2
  4. None of these
Q9MSQ3 marksselect all that apply
Which of the following statement(s) is/are true regarding JavaScript language?
  1. Any variable declared using “var” keyword has a global scope.
  2. Any variable declared using “let” keyword has a block based scope.
  3. The language supports the concept of arrays.
  4. The language uses a call stack to execute the functions in the program.
Q10MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const obj = [{
    id: "1"
}, {
    id: "2"
}, {
    id: "3"
}, {
    id: "4"
}, {
    id: "5 "
}];
const finalObj = obj.map((element) => element.id).map((element) =>
    element.trim()).map((element) => parseInt(element))).filter((element) =>
    element % 2);
console.log(finalObj, finalObj.length);
```

What will be the output of the above program, if executed?
  1. [‘1’, ‘3’, ‘5’] 3
  2. [‘2’, ‘4’] 2
  3. [1, 3, 5] 3
  4. [2, 4] 2
  5. [‘1’, ‘2’, ‘3’, ‘4’, ‘5’] 5
  6. [1, 2, 3, 4, 5] 5
Q11MSQ2 marksselect all that apply
Which of the following is/are example(s) of application state (i.e., system as seen by an individual user)?
  1. Shopping cart of an e-commerce application
  2. Loading icons
  3. Currently selected tab in a multipage / document
  4. Followed news items in a news app
Q12MSQ3 marksselect all that apply
Which of the following statement(s) is/are true?
  1. The computed properties are auto triggered when any of the reactivedependencies changes.
  2. The computed properties are cached based on their reactive dependencies.
  3. The watchers need to be manually triggered when the watched property isassigned a new value.
  4. The watchers can be defined globally, and apply to all instances of a Vuecomponent.
Q13MCQ3 marks
Which of the following is a valid function definition to return the sum of 2 numbers passed as parameter?
  1. let add = (x, y) => x + y
  2. let add = (x, y) => { x + y; }
  3. function add (x, y) { return x + y; }
  4. All of these
Q14MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below JavaScript program.

```javascript
const property1 = 10;
const obj1 = {
    property1: 20,
    property2: function () {
        console.log(property1, this.property1);
        return this.property1;
    }
}

const obj2 = {
    property1: 30,
    property2: () => {
        console.log(property1, this.property1);
        console.log(this.property2);
    }
}
obj2.property2();
```

What will be the output of the above program, if executed?
  1. 10 3020
  2. 10 30undefined
  3. 10 undefined30
  4. 10 undefinedundefined
  5. 10 3010 2020
  6. 10 undefined10 undefinedundefined
Q15MCQ2 marks
Which of the following is not a valid Vue directive?
  1. v-model
  2. v-click
  3. v-if
  4. v-show
Q16MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below javascript program.

```javascript
const a = 2;
const b = "";

const obj1 = {
  property1: 10,
  property2: 20
}

const obj2 = {
  a: 1,
  b: 2,
  ...(a && !b && { obj1 })
};

console.log(obj2);
```

What will be the output of the above program, if executed?
  1. { a: 1, b: 2, property1: 10, property2: 20 }
  2. { a: 1, b: 2, obj1: { property1: 10, property2: 20 } }
  3. { property1: 10, property2: 20 }
  4. { a: 1, b: 2 }

Answer key

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

JavaScript Fundamentals

  1. Variable Scoping:

    • var: Global or function scope.
    • let and const: Block scope.
    • Example: let x = 10;
  1. this Keyword:

    • Refers to the object it belongs to.
    • Example: this.name in an object method.
  1. Closures:

    • Functions that have access to their own scope, the outer function’s scope, and the global scope.
    • Example:

      function outer() {
        let x = 10;
        function inner() {
          console.log(x);
        }
        return inner;
      }
      const innerFunc = outer();
      innerFunc(); // Output: 10
  1. Inheritance:

    • Using Object.create() to create a new object with the specified prototype object.
    • Example:

      const parent = { name: 'Parent' };
      const child = Object.create(parent);
      console.log(child.name); // Output: 'Parent'
  1. Array Methods:

    • filter(): Creates a new array with all elements that pass the test implemented by the provided function.
    • Example:

      const numbers = [1, 2, 3, 4, 5];
      const evenNumbers = numbers.filter(num => num % 2 === 0);
      console.log(evenNumbers); // Output: [2, 4]
  1. Classes and Objects:

    • Defining classes and creating objects.
    • Example:

      class Person {
        constructor(name) {
          this.name = name;
        }
      }
      const person = new Person('Alice');
      console.log(person.name); // Output: 'Alice'
  1. Arrow Functions:

    • Shorter syntax for function expressions.
    • Example:

      const add = (a, b) => a + b;
      console.log(add(2, 3)); // Output: 5
  1. Spread Operator:

    • Allows an iterable to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected.
    • Example:

      const arr1 = [1, 2, 3];
      const arr2 = [...arr1, 4, 5];
      console.log(arr2); // Output: [1, 2, 3, 4, 5]
  1. Template Literals:

    • Allows embedded expressions.
    • Example:

      const name = 'Alice';
      console.log(`Hello, ${name}!`); // Output: 'Hello, Alice!'

Vue.js Fundamentals

  1. Vue Instance:

    • Creating a Vue instance and mounting it to the DOM.
    • Example:

      new Vue({
        el: '#app',
        data: {
          message: 'Hello Vue!'
        }
      });
  1. Data Binding:

    • Using {{ }} for text interpolation.
    • Example:

      <div id="app">
        {{ message }}
      </div>
  1. Directives:

    • Special attributes with the v- prefix.
    • Example: v-model, v-if, v-show.
  1. Computed Properties:

    • Cached based on their reactive dependencies.
    • Example:

      computed: {
        reversedMessage() {
          return this.message.split('').reverse().join('');
        }
      }
  1. Watchers:

    • Used to watch changes in data.
    • Example:

      watch: {
        message(newVal, oldVal) {
          console.log(`Message changed from ${oldVal} to ${newVal}`);
        }
      }
  1. Methods:

    • Functions defined in the Vue instance.
    • Example:

      methods: {
        greet() {
          return 'Hello!';
        }
      }
  1. Lifecycle Hooks:

    • Functions that are called at specific stages of the Vue instance lifecycle.
    • Example: created, mounted, updated, destroyed.