wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript - Practice 10

Total questions: 20

Worksheet time: 11mins

Name
Class
Date
1.

const body = document.body;

In JavaScript, what does it do?

a)

Creates a constant which reference to the body element

b)

Creates a duplication of the body element, and every change does not affect the body element

2.

const body = document.body;

What is the type of body?

(a)  

3.

How to get all elements by their tag name in JavaScript?

a)

document.getElementsByTagName();

b)

document.getElementsByTag();

c)

document.getElementsByTabName();

d)

document.getElementByTagName();

4.

How to get all elements by their class name in JavaScript?

a)

document.getElementsByClassName();

b)

document.getElementsByClass();

c)

document.getElementsByClassNames();

d)

document.getElementByClassName();

5.

document.querySelector('#bats');

What does it do in JavaScript?

a)

It uses CSS notation to find the first element with id 'bats'

b)

It uses CSS notation to find the element with class 'bats'

c)

It returns a node list of all the elements with id 'bats'

d)

It find the elements that matches a CSS selector '#bats'

6.

Are document.querySelectorAll('.bats') as same as document.getElementsByClassName('bats')?

a)

Yes

b)

No

7.

In Document Object Model (DOM), all the properties, methods and events that are available to a web developer for manipulating and creating web pages are organised into:

a)

Classes

b)

Objects

c)

Modules

d)

Variables

8.

DOM represents a webpage in what way?

a)

Dynamic structure

b)

Recursive structure

c)

Tree-like structure

d)

Hash table structure

9.

Which of the following is an appropriate event handler for input text?

a)

onclick

b)

onchange

c)

onkeyup

d)

onblur

10.

Which of the following is an appropriate event handler when the user clicks on an element?

a)

onclick

b)

onchange

c)

onkeyup

d)

onblur

11.

Identify the correct code in order to fetch the value entered in username text field?

b)

document.getElementById ("name").value

c)

document.getElementByName ("name").value

d)

None of the these

12.

How to add event handler that would be invoked when the document's body is clicked?

a)

document.onclick = function (){

// do something

};

b)

document.body.addEventListener('click', doSomethingFunction);

c)

document.click = function (){

// do something

};

d)

document.body.addEventListener('onclick', doSomethingFunction);

e)

document.body.onclick = function (){

// do something

};

13.

document.body.addEventListener('click', () => alert('You clicked!'));

Which type of the handler function is in above JavaScript code?

a)

Arrow function

b)

Lambda function

c)

Parentheses function

d)

Short function

14.

What is the difference between keydown and keypress event in JavaScript?

a)

keydown event occurs when a key is pressed

b)

keypress event occurs after keydown event and only occurs for keys that produce character input

c)

keydown event occurs when a key released

d)

keypress event occurs when a key was pushed down

e)

keydown and keyup events occur when a any key is pressed

15.

Can you remove an event in JavaScript?

a)

Yes

b)

No

16.

Which of the method following are used to navigate around the DOM tree?

a)

parentNode()

b)

nextSibling()

c)

nextDaughter()

d)

childrenNodes()

e)

previousChild()

17.

Which of the following is the container for input elements?

a)

Form

b)

Page

c)

Canvas

d)

Input

18.

How many primitive data types in JavaScript?

a)

6

b)

7

c)

5

d)

4

19.

What is callback function?

A callback is a function that is provided as an (a)   to another function.

20.

What does JSON stand for?

a)

JavaScript Object Notation

b)

Java Object Notation

c)

JavaScript Object Normalization

d)

JavaScript Object-Oriented Notation