wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Day 5 - Callbacks and Promises

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is the function to stop an interval timer?

a)

stopTimer

b)

clearInterval

c)

clearTimer

d)

shutdownTimer

2.

async function f() {

let result = 'first!';

let promise = new Promise((resolve, reject) => {

setTimeout(() => resolve('done!'), 1000);

});


result = await promise;


console.log(result);

}


f();

a)

first!

b)

done!

c)

JavaScript error

d)

Something else

3.

var p = new Promise((resolve, reject) => {

return Promise.reject(Error('The Fails!'))

})

p.catch(error => console.log(error.message))

p.catch(error => console.log(error.message))

a)

prints message once

b)

prints message twice

c)

unhandledPromiseRejectionWarning

d)

process exits

4.

var p = new Promise((resolve, reject) => {

reject(Error('The Fails!'))

})

.catch(error => console.log(error))

.then(error => console.log(error))

a)

print error and `undefined`

b)

print error twice

c)

UnhandledPromiseRejectionWarning

d)

undefined

5.

Which of the following is not a reserved word in JavaScript?

a)

interface

b)

throws

c)

program

d)

ahort

6.

<script>

let myName = "Quiz";

let myCity = "Quizzes";

console.log(`My name is ${myName}. My favorite city is ${myCity}.`)

</script>

a)

Compilation Error

b)

My name is Quiz. My favorite city is Quizzes.

c)

My name is ${myName}.My favorite city is ${myCity}

d)

0

7.

<script>

let quiz = 'Quizzes';

console.log(typeof quiz);

quiz=1;

console.log(typeof quiz);

</script>

a)

string

number

b)

string

string

c)

null

null

d)

string

integer

8.

Which of the following is an advantage of using JavaScript?

a)

Increased interactivity.

b)

Less server interaction.

c)

Immediate feedback from the users.

d)

All of the above.

9.

Which function of an Array object calls a function for each element in the array?

a)

forEach()

b)

every()

c)

forEvery()

d)

each()

10.

JavaScript is ________ language.

a)

a complied

b)

a interpreted

11.

What is the method in JavaScript used to remove the whitespace at the beginning and end of any string ?

a)

strip()

b)

trim()

c)

stripped()

d)

trimmed()

12.

How many ways are there with which we can declare a variable in javascript?

a)

Only one

b)

Three

c)

two

d)

four

13.

Is a variable named ‘apple’ same as ‘Apple’ in javascript?

a)

Yes

b)

No

c)

Only when we use ‘strict’

d)

None of the above

14.

A …………………. is a function that operates on functions, taking one or more functions as arguments, and returning new function.

a)

multiple order function

b)

higher order function

c)

lower order function

d)

new order function

15.

A ……………. is any object that can be invoked in a function invocation expression.

a)

caller object

b)

callee object

c)

callable object

d)

calling object

16.

The ……………. property of a function is a read-only property which returns the number of parameters it declares in its parameter list.

a)

length

b)

number

c)

parameter

d)

width

17.

var scope ="global scope";

function checkingscope() {

var scope ="local scope"

function f() {

return scope;

}

return f;

}

a)

It will returns the value in scope

b)

It will returns value null

c)

It will returns an exception

d)

It will show an error message

18.

(function() {

if (false) {

let f = { g() => 1 };

}

return typeof f;

})()

a)

"function"

b)

"undefined"

c)

"object"

d)

error

19.

(typeof (new (class { class () {} })))

a)

"function"

b)

"object"

c)

"undefined"

d)

Error

20.

[...[...'...']].length

a)

1

b)

2

c)

3

d)

5