Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

test1

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What is the output of the following code: if (5 > 3) { console.log('A'); } else { console.log('B'); }?

a)

C

b)

B

c)

A

d)

D

2.

How many times will the loop run: for (let i = 0; i < 5; i++) { console.log(i); }?

a)

6

b)

10

c)

5

d)

4

3.

What will be the output of the following while loop: let i = 0; while (i < 3) { console.log(i); i++; }?

a)

3

b)

0 1 2

c)

5

d)

4

4.

Given the string 'Hello World', how would you access the character 'W'?

a)

string[4]

b)

string[6]

c)

string[7]

d)

string[5]

5.

What is the result of the following array operation: let arr = [1, 2, 3]; arr.push(4);?

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

[1, 2, 3, 4, 5]

d)

[4, 1, 2, 3]

6.

How do you declare a function in JavaScript that takes two parameters and returns their sum?

a)

function total(a, b) { return a * b; }

b)

function calculate(a, b) { return a / b; }

c)

function add(x, y) { return x - y; }

d)

function sum(a, b) { return a + b; }

7.

What is function overloading and how is it implemented in languages that support it?

a)

Function overloading is a method to create functions with unique names for different tasks.

b)

Function overloading allows functions to be defined only once with fixed parameters.

c)

Function overloading is a technique to combine multiple functions into a single function call.

d)

Function overloading is a feature that allows multiple functions with the same name to coexist, differentiated by their parameter types or counts.

8.

How can you concatenate two strings in JavaScript?

a)

string1 + string2 or string1.concat(string2)

b)

string1 & string2

c)

string1 * string2

d)

string1 - string2

9.

What will be the output of the following code: let arr = [1, 2, 3]; console.log(arr[1]);?

a)

1

b)

undefined

c)

2

d)

3

10.

Explain the difference between a for loop and a while loop in programming.

a)

A for loop iterates a known number of times, while a while loop continues until a condition is false.

b)

A for loop requires a condition, while a while loop does not need any condition.

c)

A for loop is used for conditional checks, while a while loop is for fixed iterations.

d)

A for loop runs indefinitely, while a while loop stops after a set number of iterations.