Home / Past papers / MAD2 Quiz 1 / this paper

```javascript
(function () {
// some code here
})();
```
```
(() => {
// some code here
})();
```
```javascript
function () {
// some code here
}()
;
```
```javascript
(function myIIFE (arg1, arg2) {
// some code here
})(10, 20);
```
Which of the following shows the correct output for the below javascript program? ```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, []);
```
Consider the following JavaScript program. What will be logged on to the console?```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))
```
Consider the following JavaScript code. What will be logged on to the console for the statement "console.log(inning.overs[0].balls[2].batsman)"?```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()
}
})
```
Consider the following JavaScript code. What will be logged on to the console for the statement "console.log(inning.currentOver.overNo)"?```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()
}
})
```
```javascript const array = [1, 2, 3, 4, 5] const [a, b, c] = array ```

```javascript const array = [1, 2, 3, 4, 5] const [a, , c] = array ```

```javascript const array = [1, 2, 3, 4, 5] const [a, ...remaining, c] = array ```

```javascript const array = [1, 2, 3, 4, 5] const [a, b, ...remaining] = array ```
Consider the following Vue application with markup index.html and javascript file app.js. 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)?
Some Data for App Fallback Data End of Data

Some Data for App Main Data End of Data

Some Data for App Fallback Data Main Data End of Data

Some Data for App End of Data

A warning will be issue for using an undefined tag, i.e., new
Consider the following JavaScript code. What will be logged on the console?```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)
```
Hello from outside Greetings from outside

Hello from inside Greetings from inside

Hello from outside Greetings from inside

Hello from inside Greetings from outside
Consider the following JavaScript code. What will be logged on to the console?```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())
```
Test User1 Undefined

Test User1 user2@email.com

Test User1 Test User2

Test User2 user2@email.com
Consider the following Vue application with markup index.html and JavaScript app.js 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?
Consider the following Vue application with markup index.html and JavaScript app.js 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.Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Variable Declarations
var, let, and constFunctions
Event Loop
Object-Oriented Programming
this keyword and its bindingDestructuring
Component Lifecycle
beforeCreate, created, beforeMount, mountedComponents and Props
Templates and Slots
Variable Declarations
var: Function-scoped, hoisted, can be redeclaredlet: Block-scoped, hoisted but not initialized, cannot be redeclaredconst: Block-scoped, hoisted but not initialized, cannot be reassignedArrow Functions
(params) => expressionthis, arguments, super, or new.targetEvent Loop
Destructuring
const [a, b, ...rest] = array;const { name, age } = object;Lifecycle Hooks
beforeCreate: Called before the instance is initializedcreated: Called after the instance is createdbeforeMount: Called before the template is renderedmounted: Called after the template is renderedComponent Communication
These graphs provide a visual representation of the relationships between the core topics in JavaScript and Vue.js, helping to understand the structure and flow of concepts.