wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Javascript Basic

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What is a JavaScript variable?

a)

A container that holds a value

b)

A function that performs a task

c)

A way to add styles to a website

d)

A type of data

2.

How do you write a JavaScript string?

a)

"Hello World!"

b)

Hello World!

c)

'Hello World!'

d)

`Hello World!`

3.

What is the difference between = and == in JavaScript?

a)

= assigns a value to a variable and == compares values

b)

= compares values and == assigns a value to a variable

c)

= and == are the same thing

d)

= assigns a value to a variable and == assigns a value to a variable

4.

How do you create a JavaScript function?

a)

create function myFunction() {}

b)

new function myFunction() {}

c)

myFunction() {}

d)

function myFunction() {}

5.

How do you write a JavaScript alert?

a)

alert = "Hello World!";

b)

alert {Hello World!};

c)

alert("Hello World!");

d)

alert "Hello World!";

6.

How do you write a JavaScript comment?

a)

# This is a comment

b)

// This is a comment

c)

/* This is a comment */

d)

-- This is a comment

7.

How do you change the background color of an HTML element using JavaScript?

a)

element.color = "red";

b)

element.background = "red";

c)

element.style.backgroundColor = "red";

d)

element.setBackground("red");

8.

What is JavaScript used for?

a)

Creating interactive websites

b)

Making video games

c)

Designing graphics

d)

All of the answers

9.

How do you add an event listener to a button in JavaScript?

a)

button.addEventListener("click", myFunction);

b)

button.listenEvent("click", myFunction);

c)

button.onEvent("click", myFunction);

d)

button.eventListener("click", myFunction);

10.

What is the result of the following code? var x = 5; x++;

a)

4

b)

5

c)

6

d)

7

11.

What is the keyword used to create a loop in JavaScript?

a)

loop

b)

repeat

c)

for

d)

if

12.

What is the result of the following code? var x = "5"; x = x + 2;

a)

7

b)

52

c)

"52"

d)

"7"

13.

How do you print a message to the console in JavaScript?

a)

print("Hello World!");

b)

console.log("Hello World!");

c)

document.write("Hello World!");

d)

alert("Hello World!");

14.

What is the symbol used to multiply two numbers in JavaScript?

a)

x

b)

/

c)

-

d)

*

15.

What is the correct way to write an if-else statement in JavaScript?

a)

if x = 5 { } else { }

b)

if x == 5 { } else { }

c)

if (x == 5) { } else { }

d)

if x = 5 then { } else { }

16.

What is the Document Object Model (DOM)?

a)

A programming language

b)

A way to interact with HTML documents

c)

A database

d)

A type of software

17.

What is the purpose of the DOM?

a)

To create interactive websites

b)

To store data

c)

To provide a way for programming languages to access and manipulate web pages

d)

To enable web browsers to display images and text

18.

How do you select an element using JavaScript?

a)

document.getElementById()

b)

document.getElementsByClassName()

c)

document.getElementsByTagName()

d)

All of the above

19.

How do you change the text of an element using JavaScript?

a)

element.changeText()

b)

element.updateText()

c)

element.innerHTML = "new text"

d)

element.setText("new text")

20.

Can you select multiple elements at once using the getElementById method in JavaScript?

a)

Yes

b)

No