wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Javascript/DOM

Total questions: 30

Worksheet time: 19mins

Name
Class
Date
1.

What will this code display?

a)

8, 2, 1, 4, 7

b)

82147

c)

Myarray.length

d)

5

2.

What will this code display?

a)

Hello Emma

b)

Hello user

c)

Hello+user

d)

nothing

3.

What will this code display?

a)

570

b)

569

c)

568

d)

attendees

4.

What would this piece of code do?

a)

change the background color of the word demo to red

b)

change the font color of the demo element to red

c)

this is not correct

d)

styles the element with the class demo

5.

Which of these is a method?

a)

getElementById( )

b)

style

c)

document

d)

color

6.

Which line is missing to return the result of the multiplication 10 x 5 ?

a)

result

b)

number 1 * number 2 ;

c)

let result = 10 x 5 ;

d)

var result = number 1 * number 2 ;

7.

Correct this code so that

Hello!

is displayed in the paragraph

with the id "demo"

a)

add

.style.text

after ("demo")

b)

add

.innerHTML

after ("demo")

c)

add a semi colon after myFunction()

d)

Save "Hello" in a variable first

8.

What would this piece of code display?

a)

false

b)

x!=8

c)

true

d)

8

9.

Which of these methods removes the last element of an array?

a)

pop( )

b)

splice( );

c)

push( )

d)

split( )

10.

What would this piece of code display?

a)

text

b)

John, Joe, Greg, Ruth

c)

John

Joe

Greg

Ruth

d)

4

11.

What will this code do?

document.getElementById("demo").style.color = "blue";

a)

Change the text color of the element with id "demo" to blue

b)

Change the background color of the element with id "demo" to blue

c)

Remove the element with id "demo"

d)

Display an error

12.

Which method would you use to add a new element to the end of an array?

a)

unshift( )

b)

shift( )

c)

pop( )

d)

push( )

13.

Which of these is a valid way to declare a variable in JavaScript?

a)

var myVar

b)

let myVar = ;

c)

const myVar = 5

d)

myVar = 5

14.

Which function is used to convert a string to a number in JavaScript?

a)

parseInt( )

b)

String( )

c)

toString( )

d)

Number( )

15.

What does the following code do?

console.log(typeof 42);

a)

Returns the type of 42

b)

Throws an error

c)

Logs 42 to the console

d)

Logs the type of 42 to the console

16.

Which operator is used to concatenate two strings in JavaScript?

a)

-

b)

+

c)

*

d)

/

17.

What will this code return?

Math.max(1, 2, 3);

a)

2

b)

1

c)

3

d)

undefined

18.

Which of these is a valid way to create a function in JavaScript?

a)

function:myFunction() {}

b)

myFunction() {}

c)

myFunction() => {}

d)

function myFunction() {}

19.

What is the output of the following code?

javascript

console.log(typeof null);

a)

"object"

b)

"null"

c)

"undefined"

d)

"boolean"

20.

let a = [1, 2, 3];

a[10] = 99;

console.log(a.length);

a)

3

b)

10

c)

11

d)

error

21.

console.log([] + []);

a)

[]

b)

undefined

c)

"[]"

d)

"" (empty string)

22.

var x = 10;

(function() {

console.log(x);

var x = 20;

})();

a)

10

b)

20

c)

undefined

d)

error

23.

console.log([] == false);

a)

true

b)

false

c)

NaN

d)

undefined

24.

let a = 1;

a++;

console.log(a++);

a)

1

b)

2

c)

3

d)

undefined

25.

What will this code display?

a)

121

b)

123

c)

321

d)

error

26.

What will this code display?

a)

Alex likes reading, Alex likes cycling

b)

undefined likes reading, undefined likes cycling

c)

error

d)

Nothing is logged

27.

What will this code display?

a)

Name: Guest, Age: 25 ... Name: Taylor, Age: 25 ... Name: Guest, Age: 30

b)

Error

c)

Name: Taylor, Age: undefined ... etc

d)

Name: undefined, Age: undefined ... etc

28.

What will this code display?

a)

ext, null, text

b)

text, null, 0

c)

0, text, null

d)

text, null, null

29.

console.log(1 + 2 + "3" + 4 + 5);

a)

12345

b)

"3345"

c)

"3345" (as a string)

d)

"345"

30.

What will be the result when the button is clicked?

a)

The page shows the text Updated in normal font style

b)

The heading text is replaced with italicized “Updated”

c)

Nothing happens when the button is clicked

d)

A new heading is added below the existing one