wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Day-1

Total questions: 25

Worksheet time: 17mins

Name
Class
Date
1.

Which symbol is used for single-line comments in JavaScript?

a)

<!-- -->

b)

#

c)

//

d)

/* */

2.

Which function is used to display output in browser console?

a)

print()

b)

log()

c)

console.log()

d)

document.write()

3.

What does the spread operator (...) do in this context? let arr2 = [...arr1, 4, 5];

a)

Creates a nested array

b)

Copies/Expands elements

c)

Deletes elements of arr1

d)

Sorts the array

4.

Which of the following is a correct variable declaration?

a)

int x = 10;

b)

var x = 10;

c)

number x = 10;

d)

x := 10;

5.

let scores = [85, 80, 70, 92, 60];

for (let i = 0; i < scores.length; i++) {

let currentScore = scores[i];

if (currentScore >= 90) {

console.log(`Score ${currentScore}: Grade: A`);

} else if (currentScore >= 80) {

console.log(`Score ${currentScore}: Grade: B`);

} else if(currentScore >= 70){

console.log(`Score ${currentScore}: Grade: C`);

}

else {

console.log(`Score ${currentScore}: Grade: D`);

}

}

a)

Score 85: Grade: A

Score 80: Grade: B

Score 70: Grade: C

Score 92: Grade: A

Score 60: Grade: D

b)

Score 85: Grade: B

Score 80: Grade: B

Score 70: Grade: C

Score 92: Grade: A

Score 60: Grade: D

c)

Score 85: Grade: B

Score 80: Grade: B

Score 70: Grade: C

Score 92: Grade: A

Score 60: Grade: C

d)

Score 85: Grade: B

Score 80: Grade: A

Score 70: Grade: C

Score 92: Grade: A

Score 60: Grade: C

6.

What is the main difference between let and var?

a)

let is function-scoped, var is block-scoped.

b)

let is block-scoped, var is function-scoped.

c)

var cannot be reassigned.

d)

There is no difference.

7.

What does the "Spread Operator" (...) do

a)

Compresses an array into a single value

b)

Expands elements of an array or object

c)

Deletes all elements in an array

d)

Multiplies all numbers in an array

8.

What is the result of the following comparison? 5 === '5'

(a)  

9.

Which operator is used to assign a value to a variable?

a)

==

b)

===

c)

=

d)

!=

10.

What is an "Arrow Function" syntax example

a)

function myFunc() {}

b)

let myFunc = () => {}

c)

arrow function myFunc() {}

d)

let myFunc = function() {}

11.

What are "Default Parameters" in ES6?

a)

Parameters that must always be provided.

b)

Values assigned to parameters if no argument is passed during the function call.

c)

A way to name functions.

d)

Variables that only work inside a for loop

12.

The prompt() function always returns __________.

a)

Number

b)

String

c)

Boolean

d)

Object

13.

console.log() is mainly used for (a)   .

14.

Which keyword is used to define a function in JavaScript?

a)

function

b)

def

c)

fun

d)

method

15.

Which Set method returns an iterator object containing [value, value] pairs for each element?

(a)  

16.

Functions without a name are called (a)   functions.

17.

What is the "Ternary Operator" syntax?

a)

condition : true ? false

b)

condition ?? true : false

c)

if (condition) ? true

d)

condition ? value_if_true : value_if_false

18.

How do you check if a specific value exists in a Set object named mySet?

a)

mySet.exists(val)

b)

mySet.contains(val)

c)

mySet.has(val)

d)

mySet.find(val)

19.

Functions created using new Function() are called (a)   functions.

20.

Complete the loop syntax to run 5 times: for (let i = 2; (a)   ; i++)

21.

What happens if a function does not have a return statement?

(a)  

22.

Which input function allows a default value to be displayed?

a)

prompt(message)

b)

prompt(message, default)

c)

alert(message)

d)

confirm(message)

23.

Which syntax is used to create a new Set?

a)

new Set()

b)

{}

c)

[]

d)

Set()

24.

let arr1 = [1, 2];

let arr2 = [...arr1, 4, 5];

console.log(arr2);

function sum(args) {

return args.reduce((acc, val) => acc + val, 0);

}

console.log(sum(arr2)) What will be the output of console ?

a)

[ 1, 2, 4, 5 ]

10

b)

[1, 2, 3, 4, 5]

12

c)

[ 1, 2, 4, 5 ]

12

d)

[1, 2, 3, 4, 5]

10

25.

Write the code to add green to the following Set ? let colors = new Set(['red', 'blue']);

(a)