wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JS Snippet Quiz

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

What is JavaScript used for?

a)

Styling web pages

b)

Making web pages interactive

c)

Creating web page layouts

d)

Defining web page structure

2.

How can you add JavaScript to an HTML file?

a)

<script>

b)

<js>

c)

<javascript>

d)

<code>

3.

Which keyword is used to declare changing variables in JavaScript?

a)

variable

b)

int

c)

var

d)

char

4.

What does the innerHTML property do in JavaScript?

a)

Changes the content of an element

b)

Changes the style of an element

c)

Removes an element from the DOM

d)

Adds a new element to the DOM

5.

How do you select an element by its ID in JavaScript?

a)

document.getElementByClassName()

b)

document.getElementByName()

c)

document.getElementById()

d)

document.querySelector()

6.

Which method is used to add an event listener in JavaScript?

a)

addEventListener()

b)

attachEvent()

c)

onEvent()

d)

addListenEvent()

7.

What does event.preventDefault() do?

a)

Stops the event from bubbling up the DOM tree

b)

Prevents the default behavior of the event

c)

Removes the event listener from the element

d)

Stops the propagation of the event to other elements

8.

What would be the output in this code segment?

const x = 5;

x = 4;

console.log(x);

a)

error

b)

const

c)

4

d)

5