wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript

Total questions: 70

Worksheet time: 35mins

Name
Class
Date
1.

How do you write "Hello World" in an alert box?

a)

msg("Hello World");

b)

alertBox("Hello World");

c)

alert("Hello World");

d)

alert("Hello World")

2.

JavaScript code can be written directly into an HTML document using the (a)   tag.

3.

Which of the following is a primitive data type in JavaScript?

a)

Array

b)

Object

c)

Function

d)

String

4.

Which value is returned if you compare two distinct objects in JavaScript using the equality (==) operator?

a)

true

b)

false

c)

undefined

d)

NaN

5.

Which of the following keywords is used to declare a variable in JavaScript?

a)

var

b)

let

c)

const

d)

All of the above

6.

What is the scope of a variable declared with the var keyword?

a)

Function scope

b)

Block scope

c)

Global scope only

d)

None of the above

7.

How can you create a constant variable that cannot be reassigned in JavaScript?

a)

const variableName;

b)

constant variableName;

c)

var const variableName;

d)

let const variableName

8.

What will be the output of the following code snippet?

let a = 5;

let b = a;
a = 10;

console.log(b);

(a)  

9.

Which method can be used to convert a string to an integer in JavaScript?

a)

parseInt()

b)

toString()

c)

Number()

d)

parseFloat(

10.

What is the data type of null in JavaScript?

(a)  

11.

Which of the following is not a primitive data type in JavaScript?

a)

Boolean

b)

Number

c)

Symbol

d)

Array

12.

True or False

In JavaScript, you can change the value of a variable declared with const after it is initialized.

(a)  

13.

True or False

The typeof operator can be used to determine the type of a variable.

(a)  

14.

True or False

null is strictly equal to undefined in JavaScript.

(a)  

15.

In JavaScript, the (a)   operator is used to determine the data type of a variable.

16.

Variables declared with let and const have (a)   scope.

17.

A variable that is declared but not initialized will have the value (a)   .

18.

The (a)   function is used to convert a string to a floating-point number.

19.

What will be the output of the following code snippet?

var x = 3;

var y = x;

x - 7;

console.log(y);



(a)  

20.

What will be the output of the following code snippet?

const c = 10;

let d = c;

20-d

console.log(c);



(a)  

21.

What will be the output of the following code snippet?

let e = 'hello';

let f = e;

e = 'world';

console.log(f);

(a)  

22.

What will be the output of the following code snippet?

let arr1 = [1, 2, 3];

let arr2 = arr1;

arr1.push(4);

console.log(arr2);

(a)  

23.

What will be the output of the following code snippet?

let obj1 = { a: 1 };

let obj2 = obj1;

obj1.a = 5;

console.log(obj2.a);

(a)  

24.

What will be the output of the following code snippet?

let g = [1, 2];

let h = [...g];

g.push(3);

console.log(h);

(a)  

25.

What will the following expression evaluate to?

3 + 2 * 2

(a)  

26.

Which operator is used to concatenate two strings in JavaScript?

a)

+

b)

&

c)

&&

d)

||

27.

Which of the following operators has the highest precedence?

a)

*

b)

+

c)

-

d)

&&

28.

What will the following expression evaluate to?

4 + 5 + "7"

(a)  

29.

Which operator is used to compare both value and type in JavaScript?

a)

==

b)

===

c)

=

d)

!=

30.

What will the following expression evaluate to?

10 % 3



(a)  

31.

Which operator is used to increment a variable in JavaScript?

(a)  

32.

True or False

The addition operator (+) has a higher precedence than the multiplication operator (*) in JavaScript

(a)  

33.

The logical OR operator (||) has lower precedence than the logical AND operator (&&).

(a)  

34.

The (a)   operator is used to find the remainder of a division operation.

35.

True or False:

The for loop is typically used when the number of iterations is known beforehand.

(a)  

36.

In JavaScript, the do...while loop is an example of a (a)   loop.

37.

Which of the following methods adds elements to the end of an array?

a)

push()

b)

pop()

c)

shift()

d)

unshift()

38.

True or False:

Arrays in JavaScript can hold elements of different data types.

(a)  

39.

Arrays are indexed starting from (a)   .

40.

Which method removes the first element from an array and returns it?

a)

shift()

b)

unshift(

c)

pop()

d)
  • push()

41.

Array.isArray(myArray) returns true if myArray is an array.

a)

True

b)

False

42.

Which method returns the index within the calling String object of the first occurrence of the specified value?

a)

indexOf()

b)

lastIndexOf()

c)

search()match()

43.

In JavaScript, the while loop executes a block of code as long as a specified (a)   is true.

44.

Which loop executes a block of code at least once, and then repeats the loop as long as a specified condition is true?

a)

do...while

b)

for...in

c)

while

d)

for

45.

True or False:

break statement is used to terminate the execution of a loop.

(a)  

46.

The Math.random() function generates a random number between ... and ....

a)

1 & 5

b)

0 & 1

c)

5 &10

d)

0 & 9

47.

The .map() method modifies the original array.

a)

True

b)

False

c)

Both

d)

No answer

48.

Which method is used to find the length of a string in JavaScript?

a)

length

b)

.length()

c)

length()

d)

All the above

49.

Which method is used to find the length of a string in JavaScript?

a)

length

b)

.length()

c)

length()

d)

All the above

50.

Which of the following methods is used to concatenate two strings?

(a)  

51.

What will be the output of the following code?

let str = "Hello, World!";

console.log(str.toUpperCase());

(a)  

52.

What does the .includes() method do in JavaScript?

a)

Checks if a string contains a specified value

b)

Finds the index of a value

c)

Splits a string into an array

d)

Replaces a part of a string

53.

What does the .includes() method do in JavaScript?

a)

Checks if a string contains a specified value

b)

Finds the index of a value

c)

Splits a string into an array

d)

Replaces a part of a string

54.

What will be the output of the following code?

let str = "JavaScript";

console.log(str.charAt(4));

(a)  

55.

How do you replace "Hello" with "Hi" in a string?

a)

str.replace("Hello", "Hi")

b)

str.change("Hello", "Hi")

c)

str.swap("Hello", "Hi")

d)

str.modify("Hello", "Hi")

56.

Which method is used to split a string into an array?

(a)  

57.

What does the break statement do in a loop?

a)

Skips one iteration

b)

Stops the loop completely

c)

Restarts the loop

d)

Throws an error

58.

What does the Math.max(2, 8, 5, 10, 3) function return?

(a)  

59.

Which of the following is NOT a valid DOM collection type?

a)

ElementArray

b)

All are valid

c)

HTMLCollection

d)

NodeList

60.

Which property returns the number of child elements a DOM element has?

a)

childElementCount

b)

childNodes.length

c)

children.count

d)

element.childCount

61.

What is the purpose of querySelectorAll()?

a)

To select all elements matching a CSS selector

b)

To create new DOM elements

c)

To remove elements from the DOM

d)

To select a single element

62.

Which property is used to modify the CSS styles of a DOM element?

b)

element.css

c)

element.className

63.

Which method returns a collection of elements with a specific class name?

a)

document.getElementsByClassName()

b)

document.querySelectorAll()

c)

document.getElementById()

d)

document.getElementsByTagName()

64.

What does DOM stand for?

(a)  

65.

Which keyword is used to wait for a Promise to resolve inside an async function?

a)

wait

b)

yield

c)

await

d)

pause

66.

What is the primary advantage of asynchronous programming in JavaScript?

a)

It prevents blocking the main thread

b)

It executes code sequentially

c)

It makes all operations synchronous

d)

It reduces code complexity

67.

Which of the following correctly defines a function using a function declaration?

a)

function myFunc() {}

b)

function: myFunc() {}

c)

var myFunc = () => {}

d)

def myFunc() {}

68.

How do you create an instance of a class?

b)

new MyClass();

c)

MyClass();

d)

MyClass.create();

69.

What is the purpose of the extends keyword in a JavaScript class?

a)

To define a static method

b)

To inherit from a parent class

c)

To bind methods permanently

d)

To encapsulate private properties

70.

How do you properly write a while loop?

a)

while (i < 10) {}

b)

while { i < 10 }

c)

while i < 10 {}

d)

while i = 10 {}