wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

24/01/2024

Total questions: 15

Worksheet time: 3mins

Name
Class
Date
1.

What is JavaScript primarily used for?

a)

Database Management

b)

Creating Dynamic Web Pages

c)

Network Security

d)

Graphic Designing

2.

Which keyword is used to declare a constant variable in JavaScript?

a)

let

b)

const

c)

var

d)

constant

3.

What is the purpose of the document.getElementById() function?

a)

To get the value of an input field

b)

To select an HTML element by its id

c)

To create a new HTML element

d)

To delete an HTML element

4.

What is the purpose of the addEventListener method in JavaScript?

a)

To change the style of an element

b)

To create a new HTML element

c)

To add an event handler to an element

d)

To remove an element from the DOM

5.

How do you declare a function expression in JavaScript?

a)

function myFunction() {}

b)

const myFunction = function() {}

c)

let myFunction = () => {}

d)

both b and c

6.

What does the typeof operator return for an array

a)

array

b)

object

c)

list

d)

typeof doesn't work for arrays

7.

In JavaScript, which loop is ideal for iterating over the elements of an array?

a)

while

b)

Do-while

c)

for-in

d)

for

8.

Which keyword is used to exit a loop prematurely in JavaScript?

a)

break

b)

exit

c)

return

d)

end

9.

What does the NaN value represent in JavaScript?

a)

Not a Number

b)

Negative And Null

c)

Null or Negative

d)

Not Any Number

10.

How do you check if a variable is of type "string" in JavaScript?

a)

typeof variable === 'string'

b)

variable.type === 'string'

c)

typeOf(variable) == 'string'

d)

variable instanceof String

11.

What is the difference between null and undefined in JavaScript?

a)

They are interchangeable

b)

null represents an empty or non-existent value, while undefined is the absence of a value

c)

undefined represents an empty or non-existent value, while null is the absence of a value

d)

There is no difference

12.

What is the purpose of the querySelector() method in JavaScript?

a)

To select the first element that matches a specified CSS selector

b)

To create a new HTML element

c)

To modify the style of an element

d)

To remove an element from the DOM

13.

What is the difference between a static method and an instance method in a class?

a)

Static methods are called on instances, while instance methods are called on the class itself

b)

Static methods are defined using the this keyword, while instance methods use self

c)

Static methods are called on the class itself, while instance methods are called on instances

d)

To remove an element from the DOMThere is no difference between static and instance methods

14.

How do you inherit from multiple classes in JavaScript?

a)

Using the inherits keyword

b)

JavaScript does not support multiple inheritance

c)

Using the mixins keyword

d)

Using the extends keyword for each parent class

15.

How do you check if a class has a particular method in JavaScript?

a)

Using the methodExists operator

b)

With the hasMethod function

c)

By inspecting the prototype of the class

d)

There is no direct way to check for a method