MAD Study Hub

Home / Past papers / MAD2 Quiz 1 / this paper

IIT M DIPLOMA AN4 EXAM QPD4 29 Oct 2023 - 29 Oct 2023

MAD2 Quiz 116 questions50 marks14 MCQ · 2 MSQDiploma / QPD4
Elapsed 00:00
Q1MCQ2 marks
Which of the following statements is true regarding, var, let & const?
  1. A variable created using “var” is always added as a property to the global object.
  2. A variable created using “let” is never added as a property to the global object.
  3. A variable created using “const” is not hoisted.
  4. All of these
Q2MCQ2 marks
Which of the following is not a valid IIFE (Immediately Invoked Function Expression)?
  1. question figure
    text
    ```javascript
    (function () {
        // some code here
    })();
    ```
  2. question figure
    text
    ```
    (() => {
      // some code here
    })();
    ```
  3. question figure
    text
    ```javascript
    function () {
      // some code here
    }()
    ;
    ```
  4. question figure
    text
    ```javascript
    (function myIIFE (arg1, arg2) {
        // some code here
    })(10, 20);
    ```
Q3MCQ2 marks
Which of the following is not an example of application or UI (ephemeral) state?
  1. User Preferences & Recommendations
  2. Loading Icons
  3. Dashboard Displays
  4. User Database of NPTEL
Q4MCQ2 marks
Which of the following statements are correct regarding a variable declared using var keyword?
  1. Variable is always globally scoped.
  2. Variable declared inside the function can be accessed outside the function.
  3. Variable declared inside a function can only be accessed inside the function.
  4. None of these
Q5MSQ3 marksselect all that apply
Which of the following is/are correct definition(s) of an arrow function that accepts 2 numbers and return the addition of their squares?
  1. let func = (num1, num2) => return num1*num1 + num2*num2;
  2. let func = (num1, num2) => num1*num1 + num2*num2;
  3. let func = (num1, num2) => { return num1*num1 + num2*num2; }
  4. let func = (num1, num2) => { num1*num1 + num2*num2; }
Q6MSQ3 marksselect all that apply
Which of the following statement(s) is/are true regarding event loop in javascript?
  1. The event loop makes sure that each function is processed (or executed)completely before any other function is executed.
  2. The event loop takes the function from the callback queue, and sends thefunction to the call stack for execution.
  3. The event loop can stop any function in running state to allow some otherfunction to run on priority.
  4. All of these
Q7MCQ4.5 marks
Which of the following shows the correct output for the below javascript program? question figure Which of the following shows the correct output for the below javascript program?
Text of the picture (copyable)
```javascript
var a = 100;

const obj1 = {
    a : 10,
    b : 20,

    func : function (a) {
        console.log("Value:", a);
    }
}

const obj2 = {
    a : 40,
    b : 50,

    func : function (a) {
        this.func(a);
    }
}

obj2.func.apply(obj2, []);
```
  1. Value: 100
  2. The program will crash due to repeated function calls
  3. Value: 40
  4. Value: 10
Q8MCQ4.5 marks
Consider the following JavaScript program. question figure Consider the following JavaScript program. What will be logged on to the console?
Text of the picture (copyable)
```javascript
const userDetails = {
  name: 'user1',
  email: 'user1@email.com',
  password: '12345',
}

function user({ userName: name = 'Name1', password }) {
  return `Username: ${name}, Password: ${password}`
}
console.log(user(userDetails))
```
  1. Username: Name1, Password: 12345
  2. Username: user1, Password: 12345
  3. Username: Name1, Password: undefined
  4. Username: user1, Password: undefined
Q9MCQ4.5 marks
Consider the following JavaScript code. question figure Consider the following JavaScript code. What will be logged on to the console for the statement "console.log(inning.overs[0].balls[2].batsman)"?
Text of the picture (copyable)
```javascript
class Ball {
  constructor(batsman, run = 0, extra = false) {
    this.batsman = batsman
    this.run = run
    this.extra = extra
  }
}

class Over {
  constructor(overNo) {
    this.overNo = overNo
    this.balls = []
  }
}

class Inning {
  constructor(team, striker, nonStriker) {
    this.team = team
    this.striker = striker
    this.nonStriker = nonStriker
    this.overs = []
    this.currentOver = new Over(1)
  }

  changeStrike() {
    ;[this.striker, this.nonStriker] = [this.nonStriker, this.striker]
  }

  changeOver() {
    this.currentOver = new Over(this.currentOver.overNo + 1)
    this.changeStrike()
  }
}

const inning = new Inning('India', 'Rohit', 'Gill')
const runs = [0, 4, 3, 6, 2, 6, 4, 1, 3]
runs.forEach((run, index) => {
  const ball = new Ball(inning.striker, run)
  inning.currentOver.balls.push(ball)
  if (run % 2 == 0) {
    inning.changeStrike()
  }
  if ((index + 1) % 3 == 0) {
    inning.overs.push(inning.currentOver)
    inning.changeOver()
  }
})
```
  1. Rohit
  2. Gill
  3. Virat
  4. None of these
Q10MCQ4.5 marks
Consider the following JavaScript code. question figure Consider the following JavaScript code. What will be logged on to the console for the statement "console.log(inning.currentOver.overNo)"?
Text of the picture (copyable)
```javascript
class Ball {
  constructor(batsman, run = 0, extra = false) {
    this.batsman = batsman
    this.run = run
    this.extra = extra
  }
}

class Over {
  constructor(overNo) {
    this.overNo = overNo
    this.balls = []
  }
}

class Inning {
  constructor(team, striker, nonStriker) {
    this.team = team
    this.striker = striker
    this.nonStriker = nonStriker
    this.overs = []
    this.currentOver = new Over(1)
  }

  changeStrike() {
    ;[this.striker, this.nonStriker] = [this.nonStriker, this.striker]
  }

  changeOver() {
    this.currentOver = new Over(this.currentOver.overNo + 1)
    this.changeStrike()
  }
}

const inning = new Inning('India', 'Rohit', 'Gill')
const runs = [0, 4, 3, 6, 2, 6, 4, 1, 3]
runs.forEach((run, index) => {
  const ball = new Ball(inning.striker, run)
  inning.currentOver.balls.push(ball)
  if (run % 2 == 0) {
    inning.changeStrike()
  }
  if ((index + 1) % 3 == 0) {
    inning.overs.push(inning.currentOver)
    inning.changeOver()
  }
})
```
  1. 1
  2. 2
  3. 3
  4. 4
Q11MCQ3 marks
Which of the following is not a correct way to destructure (or unpack) an array?
  1. question figure
    text
    ```javascript
    const array = [1, 2, 3, 4, 5]
    const [a, b, c] = array
    ```
  2. question figure
    text
    ```javascript
    const array = [1, 2, 3, 4, 5]
    const [a, , c] = array
    ```
  3. question figure
    text
    ```javascript
    const array = [1, 2, 3, 4, 5]
    const [a, ...remaining, c] = array
    ```
  4. question figure
    text
    ```javascript
    const array = [1, 2, 3, 4, 5]
    const [a, b, ...remaining] = array
    ```
Q12MCQ3 marks
Consider the following Vue application with markup index.html and javascript file app.js. question figure Consider the following Vue application with markup index.html and javascript file app.js.
Text of the picture (copyable)
index.html:

```html
<div id = "app">
    Some Data for App
    <new>Fallback Data</new>
</div>
<script src = "app.js"> </script>
```

app.js:

```javascript
Vue.component('new', {
    template : `<div>
        <slot>Main Data</slot>
        <h1>End of Data</h1>
    </div>`
});

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

What will be rendered on the browser screen (ignore the formatting and styling)?
  1. question figure
    text
    Some Data for App
    Fallback Data
    End of Data
  2. question figure
    text
    Some Data for App
    Main Data
    End of Data
  3. question figure
    text
    Some Data for App
    Fallback Data
    Main Data
    End of Data
  4. question figure
    text
    Some Data for App
    End of Data
  5. question figure
    text
    A warning will be issue for using an undefined tag, i.e., new
Q13MCQ3 marks
Consider the following JavaScript code. question figure Consider the following JavaScript code. What will be logged on the console?
Text of the picture (copyable)
```javascript
let sayHello = 'Hello from outside'
var greet = 'Greetings from outside'

{
    let sayHello = 'Hello from inside'
    var greet = 'Greetings from inside'
}

console.log(sayHello)
console.log(greet)
```
  1. question figure
    text
    Hello from outside
    Greetings from outside
  2. question figure
    text
    Hello from inside
    Greetings from inside
  3. question figure
    text
    Hello from outside
    Greetings from inside
  4. question figure
    text
    Hello from inside
    Greetings from outside
Q14MCQ3 marks
Consider the following JavaScript code. question figure Consider the following JavaScript code. What will be logged on to the console?
Text of the picture (copyable)
```javascript
function getName () {
  return this.userName
}

const getEmail = () => this.email

const User1 = { userName: 'Test User1', email: 'user1@email.com' }
const User2 = { userName: 'Test User2', email: 'user2@email.com' }

User1.getName = getName
User2.getEmail = getEmail

console.log(User1.getName())
console.log(User2.getEmail())
```
  1. question figure
    text
    Test User1
    Undefined
  2. question figure
    text
    Test User1
    user2@email.com
  3. question figure
    text
    Test User1
    Test User2
  4. question figure
    text
    Test User2
    user2@email.com
Q15MCQ3 marks
Consider the following Vue application with markup index.html and JavaScript app.js question figure Consider the following Vue application with markup index.html and JavaScript app.js
Text of the picture (copyable)
index.html
```html
<div id="app"></div>
```
app.js
```javascript
new Vue({
  el: '#app',
  template: `<div> Total Count: {{count}}</div>`,
  data: {
    count: 0,
  },
  beforeCreate() {
    this.count += 1
  },
  created() {
    this.count += 1
  },
  beforeMount() {
    this.count += 1
  },
  mounted() {
    this.count += 1
  },
})
```
Suppose the application is running on “http://127.0.0.1:8080”. What will be rendered by the browser?
  1. Total Count: 2
  2. Total Count: 3
  3. Total Count: 4
  4. Total Count: 5
Q16MCQ3 marks
Consider the following Vue application with markup index.html and JavaScript app.js question figure Consider the following Vue application with markup index.html and JavaScript app.js
Text of the picture (copyable)
index.html
```html
<div id="app"></div>
```

app.js
```javascript
const Counter = {
  template: `<div><b>{{counter}}</b><button @click='changeStatus'>
Click Me </button></div>`,
  props: ['initial'],
  data() {
    return {
      wasClicked: false,
      counter: this.initial,
    }
  },
  methods: {
    changeStatus() {
      this.wasClicked = !this.wasClicked
    },
  },
  watch: {
    wasClicked(val) {
      if (val) {
        this.counter += 1
      }
    },
  }
}

new Vue({
  el: '#app',
  template: `<div><counter :initial=3 /></div >`,
  components: {
    counter: Counter,
  },
})
```

Suppose the application is running on "http://127.0.0.1:8080". What will be the value of data property "counter" of "Counter" component if the user clicks on click me button 5 times.
  1. 0
  2. 5
  3. 6
  4. 8

Answer key

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

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

JavaScript Fundamentals

  1. Variable Declarations:

    • var, let, and const
    • Scoping rules: var is function-scoped, let and const are block-scoped.
    • Hoisting: var is hoisted and initialized with undefined, let and const are hoisted but not initialized.
  1. Immediately Invoked Function Expressions (IIFE):

    • Syntax: (function() { /* code */ })();
    • Arrow function IIFE: ( () => { /* code */ } )();
  1. Arrow Functions:

    • Syntax: (params) => { /* code */ }
    • Concise body: (params) => expression
  1. Event Loop:

    • Call stack, callback queue, and event loop mechanism.
    • Non-blocking I/O operations.
  1. Object Methods and this:

    • apply, call, and bind methods.
    • Context binding and this keyword.
  1. Destructuring:

    • Array destructuring: const [a, b, ...rest] = array;
    • Object destructuring: const { prop1, prop2 } = object;
  1. Classes and Objects:

    • Class syntax: class MyClass { constructor() { /* code */ } }
    • Instance properties and methods.

Vue.js Fundamentals

  1. Vue Instance:

    • Lifecycle hooks: beforeCreate, created, beforeMount, mounted.
    • Data properties and methods.
  1. Components:

    • Component registration: Vue.component('my-component', { /* options */ })
    • Props and slots.
  1. Templates and Directives:

    • Template syntax: {{ message }}
    • Directives: v-if, v-for, v-on, v-bind.