wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

JavaScript Assessment-2

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Arrays are written in JavaScript using which of the following?

a)

round brackets ()

b)

curly brackets {}

c)

double quotes ""

d)

square brackets []

2.

Which of the following syntax for the function definition is appropriate?

a)

return_type function function_name(parameter1, parameter2, ...) { /*Function's body*/ }

b)

function function_name(parameter1, parameter2, ...) { /*Function's body*/ }

c)

return_type function_name(parameter1, parameter2, ...) { /*Function's body*/ }

d)

function function_name(parameter1, parameter2, ...) as return_type { /*Function's body*/ }

3.

What will be the output of the following JavaScript code?

<script>

function addition(a, b)

{ return a+b; }

document.getElementById("test").innerHTML = addition;

</script>

a)

SyntaxError

b)

ValueError

c)

0

d)

function addition(a, b) { return a+b; }

4.

Which is the correct syntax to access an object property in JavaScript?

a)

objectName:propertyName

b)

objectName.propertyName

c)

objectName["propertyName"]

d)

Both B. and C.

5.

In JavaScript, which attribute is utilised to determine a string's length?

a)

strlen

b)

len

c)

length

d)

Length

6.

Which is the correct JavaScript statement to define string as object?

a)

var s = new String("Let us learn JS!");

b)

var s = String("Let us learn JS!");

c)

var s = "Let us learn JS!"

d)

All of the above

7.

Which is/are the valid JavaScript method(s) to extract string parts?

a)

slice(start, end)

b)

substring(start, end)

c)

substr(start, length)

d)

All of the above

8.

How can a number be converted into a string using JavaScript?

a)

parseInteger()

b)

intToString()

c)

toString()

d)

All of the above

9.

What will be the output of the following JavaScript code?

<script>

const myArray = ['h', 'e', 'l', 'l', 'o'];

document.write(myArray[1]);

document.write(myArray[2]);

</script>

a)

he

b)

el

c)

ValueError

d)

TypeError

10.

Which JavaScript method is used to call a function (a callback function) once for each array element?

a)

for()

b)

traverse()

c)

forEach()

d)

None of these

11.

What will be the output of the following JavaScript code?

<script>

const arr = [1, 2, 3];

let result = 0;

arr.forEach(myFunction);

document.write("Result: " , result)

function myFunction(value, index, array) { result += value; }

</script>

a)

Result: 6

b)

Result: 123

c)

Result: 1,2,3

d)

ValueError

12.

Which JavaScript method is used to create a new array with array elements that passes a test?

a)

forEach()

b)

map()

c)

forMap()

d)

filter()

13.

What will be the output of the following code snippet?

<script>

var a = "Javascript";

var result = a.substring(2, 5);

document.write(result);

</script>

a)

ava

b)

vas

c)

avas

d)

vasc

14.

What will be the output of the following code snippet?

<script>

var x=01;

var y=99;

var res=eval("x+y");

document.write(res);

</script>

a)

100

b)

0199

c)

x+y

d)

None of these

15.

What will be the output for the following code snippet?

<p id="example"></p>

<script>

function Func() {

document.getElementById("example").innerHTML=Math.sqrt(81);

}

</script>

a)

9

b)

81

c)

Error

d)

None of these

16.

What will be the output of the following code snippet?

var a = 1;

var b = 0;

while (a <= 3) {

a++;

b += a * 2;

print(b);

}

a)

4 10 18

b)

1 2 3

c)

1 4 7

d)

None of these

17.

Which function is used to serialize an object into a JSON string in Javascript?

a)

parse()

b)

stringify()

c)

convert()

d)

None of the above

18.

What will be the output of the following code snippet?

let sum = 0;

const a = [1, 2, 3];

a.forEach(getSum);

print(sum);

function getSum(ele) { sum += ele; }

a)

6

b)

1

c)

2

d)

None of these

19.

How to stop an interval timer in Javascript?

a)

clearTimer

b)

clearInterval

c)

intervalOver

d)

None of the above

20.

What is the output of the following code snippet?

print(NaN === NaN);

a)

true

b)

false

c)

undefined

d)

Error