wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript - Practice 8

Total questions: 40

Worksheet time: 21mins

Name
Class
Date
1.

Which of the following is an extension of JavaScript file?

a)
.jscp
b)
.js
c)
.css
d)

.jp

e)

.jt

2.

How important is the JavaScript in web development?

a)

It decorates the webpages effectively

b)

It makes the website more interactive and user-friendliness

c)

It makes the front-end of a website

d)

It is the standard markup language for creating web pages

3.

How do you get JavaScript on your computer?

a)

You don't have to get or download JavaScript because it is already running in your browser

b)

You have to download a JavaScript editor to run JavaScript code

c)

You have to download Node.js runtime to run JavaScript code

d)

You don't have to get it because your operating system is written in JavaScript

4.

Can JavaScript change HTML content?

a)

No

b)

Yes

5.

How to find an HTML element by its id?

a)

document.getElementById()

b)

document.getElementByIDd()

c)

document.getElementsById()

d)

document.getElementByClassName()

6.

Which of the following symbols is used for JavaScript comments?

a)
\\
b)
^
c)
?
d)
//
e)

<!-- -->

7.

Indicates the beginning and the end of the JavaScript section in HTML files.

a)
<html> </html>
b)
<style> </style>
c)
<article> </article>
d)
<script> </script>
8.

How to show a pop-up message to the user on browser?

a)

alert

b)

prompt

c)

console.log

d)

<p> tag

e)

Console.WriteLine

9.

Which message will the user see on browser?

a)
"Hello user"
b)

Nothing to show

c)
"Goodbye user"
d)
"message + user"
10.

How to declare a new variable in JavaScript?

a)
var newVariable = 5;
b)
Variable int = new Variable();
c)
var 5 = myVariable;
d)
int var = 5;
11.

Write an expression in if-statement

"His name is Fred and he is less than 16 years old"

a)

if (name = "fred" && age < 16 )

b)

if (name === "fred" && age < 16 )

c)

if (name = "fred" || age < 16 )

d)

if (name === "fred" || age < 16 )

e)

if (name == 'Fred' && age < 16)

12.

A variable can be declared with keyword (a)  

13.

What is an array?

a)
Shapes
b)
Sizes
c)
Options
d)

List of data

14.

What type of variable:

var age = "5";

a)

int

b)

float

c)

boolean

d)

string

e)

number

15.

What is the first index value of an array?

a)

2

b)

-1

c)

0

d)

1

16.

What is an alert box in browser?

alert("Hello world!");

a)

The alert box takes the focus away from the current window, and forces the user to read the message.

b)

It warns (someone) of a danger, threat, or problem, typically with the intention of having it avoided or dealt with.

c)

An area on a page that is to be filled in or that is set off by a border.

d)

The state of being watchful for possible danger.

17.

What will this code display?

a)

8, 2, 1, 4, 7

b)

82147

c)

Myarray.length

d)

5

e)

6

18.

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)

style the element with the class demo

e)

set the text in demo element

19.

Which of these is a method?

a)

getElementById( )

b)

style

c)

document

d)

color

e)

getElementsById( )

20.

Which of the following is the correct JavaScript format for a comment?

a)

// the text

b)

/the text/

c)

*/the text/*

d)

\\the text

e)

# the text

21.
Which of the following best describes what a function is used for?
a)
they create new variable commands
b)
they are used for difficult math formulas
c)
they are reusable pieces of code that can be called any time in the program
d)
they allow for the use of mathematical operators
22.

What is the correct data type of the variable x?

(a)  

23.

Fill in the blank to complete the function in JavaScript

(a)  

24.

JavaScript : What is the alert display for text3 ?

a)

John Doe

b)

JohnDoe

c)

"John" " " "Doe"

d)

"JohnDoe"

25.

What will be the output?

console.log(1 === '1');

a)

true

b)

false

26.

What will be the output?

console.log(1 == '1');

a)

true

b)

false

27.

What will be the output?

console.log(1 == '01');

a)

true

b)

false

28.

What will be the output?

console.log('8' + 7);

a)

15

b)

87

c)

some error

29.

What will be the output?

console.log(8 + '7');

a)

15

b)

87

c)

some error

30.

What will be the output?

console.log(10 / 0);

a)

some error

b)

Infinity

c)

0

31.

What will be the output?

console.log('' == 0); //there is an empty string on the statement

a)

true

b)

false

32.

What will be the output?

console.log(NaN == NaN);

a)

true

b)

false

33.

What will be the output?

let number = 0;

console.log(number++);

console.log(++number);

console.log(number);

a)

1

2

2

b)

0

2

2

c)

0

1

2

34.

What will be the output?

const obj = { a: 'one', b: 'two', a: 'three' };

console.log(obj);

a)

some error

b)

{ a: 'three', b: 'two'}

c)

{ a: 'one', b: 'two', a: 'three' }

35.

Select the falsy values!

(more than one correct answer is possible)

a)

''

b)

'1'

c)

0

d)

null

e)

true

36.

What will be console logged into the terminal?

a)

1

b)

2

c)

{number: 1}

d)

3

37.

What property tells you how many items are in an array?

a)

count

b)

sum

c)

length

d)

items

38.

What will this code log?

a)

3

b)

undefined

c)

1,2,3,4

d)

arr

39.

Which of the following code will return `undefined` using the following array?

const numbers = [3, 1];

a)

numbers[0]

b)

numbers[2-1]

c)

numbers[3]

d)

numbers[numbers.length -1]

40.

All the elements in an array must be of the same type?

a)

True

b)

False

c)

Yes