wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Day-3

Total questions: 25

Worksheet time: 18mins

Name
Class
Date
1.

An array is a collection of __________.

a)

single value

b)

multiple values

c)

only numbers

d)

only strings

2.

What will console.log(fruits[0]) output if let fruits = ["apple", "banana"];?

(a)  

3.

function createCounter() {

let count = 1;

return {

increment: (val) => {

count*val

console.log(count*val)

},

decrement: (val) => {

let final = val/2 == 2 ? val + 2 : val + 4 ;

console.log(final)

},

};

}

const counter = createCounter();

counter.increment(10);

counter.increment();

counter.decrement(4);

counter.decrement(30);

(a)  

4.

How do you add a new property gender to object person?

a)

person.add("gender")

b)

person.gender = "male"

c)

person.push("gender")

d)

person.new("gender")

5.

How do you access the name of the first object in array users?

b)

users[0].name

c)

users[1].name

d)

users["name"]

6.

Which method finds the first object matching a condition?

a)

find()

b)

filter()

c)

map()

d)

forEach()

7.

let person = { name: "John", age: 25 };

let entries = Object.entries(person);

let newObj = Object.fromEntries(entries.reverse());

console.log(Object.keys(newObj)[0]);

Waht will be the Output ?

(a)  

8.

In JavaScript objects, keys are typically (a)   and values can be any data type.

9.

Lexical scope means __________.

a)

Scope determined at runtime

b)

Scope determined where function is defined

c)

Scope determined where function is called

d)

No scope

10.

In lexical scope, inner functions can access __________ variables.

a)

Only local

b)

Only global

c)

Outer and global

d)

None

11.

What is a closure in JavaScript?

a)

A function inside a loop

b)

A function that remembers outer variables

c)

A global variable

d)

A global variable

12.

What is the output?

function outer() { let x = 5; return () => x + 2; }

console.log(outer()());

a)

5

b)

2

c)

7

d)

undifined

13.

Closures are useful for data (a)   .

14.

What is output?

for(var i=0;i<3;i++){

setTimeout(()=>console.log(i),1000);

}

a)

0 1 2

b)

3 3 3

c)

0 0 0

d)

Error

15.

Closures unintentionally modifying outer variables is a problem when using __________.

a)

Global variables

b)

Block-scoped variables

c)

Function parameters

d)

Constants

16.

Each closure returned by a function has its own (a)   variables.

17.

How do you add a method to a constructor’s prototype?

a)

Person.method = function(){}

b)

Person.prototype.method = function(){}

c)

Person.__proto__ = function(){}

d)

Person.__proto__ = function(){}

18.

let matrix = [

[19, 24, 36],[43, 25, 12],[18, 36, 19]

];

matrix[2][1] = 10,

matrix[1][0] = 32,

console.log(matrix[2][0])

console.log(matrix[1][2])

console.log(matrix[1][0])

console.log(matrix[2][2])

What will be the output ?

(a)  

19.

All functions automatically have a (a)   property.

20.

ES6 Classes are __________ in JavaScript.

a)

Functions

b)

Syntactic sugar over prototypes

c)

Objects

d)

Arrays

21.

What is the output?

class Test {

method() { console.log("Hi"); }

}

let t = new Test();

t.method();

a)

Hi

b)

Error

c)

undifined

d)

null

22.

What will happen if super() is not called in subclass constructor?

a)

Works normally

b)

Throws ReferenceError

c)

Ignored

d)

Undefined behavior

23.

let students = [

{ name: "Suresh", grades: [85, 90, 78 , 90 , 75] },

{ name: "Ramesh", grades: [92, 88, 85 , 60 , 86] }

];

for(i=0;i<students.length ; i++){

for(j=0; j<students[i].grades.length; j++){

grade =students[i].grades[j]

if(grade > 90){

students[i].grades[j] = "Grade A1"

}else if(grade <=90 && grade >85 ){

students[i].grades[j] = "Grade A2"

}else if(grade <=85 && grade >75 ){

students[i].grades[j] = "Grade B1"

}

else if(grade <=75 && grade >60 ){

students[i].grades[j] = "Grade B2"

}else{

students[i].grades[j] = "Grade c"

}

}

} How many Grade B1s did Suresh get, and how many Grade B2s did Ramesh get?

(a)  

24.

Prototype inheritance is implemented using __________.

a)

Classes

b)

Objects

c)

Functions

d)

Interfaces

25.

Object.create() creates an object with a specified (a)   .