wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz For JavaScript

Total questions: 50

Worksheet time: 25mins

Name
Class
Date
1.

What is JavaScript primarily used for?

a)

a. Creating desktop applications

b)

B. Creating backend applications

c)

c. Creating dynamic web pages

d)

d. Handling 3D graphics

2.

In which environment does JavaScript run?

a)

a. Browser

b)

b. Server

c)

c. Both a and b

d)

d. None of the above

3.

Which command is used to print to the console in JavaScript?

a)

a. print()

b)

b. console.log()

c)

c. echo()

d)

d. document.write()

4.

Which keyword is used to declare a variable in JavaScript?

a)

a. var

b)

b. let

c)

c. const

d)

d. All of the above

5.

  What is the difference between == and === in JavaScript?

a)

a) == compares values and data types, while === compares only values

b)

b) == compares values after type coercion, while === compares both values and data types without type coercion.

c)

c) == is used for assignment, while === is used for comparison.

d)

d) There is no difference; both == and === work the same way.

6.

Can a variable declared with const change its value?

a)

Yes

b)

No

7.

What happens if you access an undeclared variable?

a)

a. undefined

b)

b. Throws an error

c)

c. null

d)

d. An empty string

8.

What is the result of the following code?

var a = 5;

let b = 10;

const c;

a)

a. Variables a, b, and c are all valid

b)

b. Error at variable c

c)

c. a and b are invalid

d)

d. The program runs without error

9.

What is the result of the following code?

console.log(y); 

a)

a. undefined

b)

b. Throws an error

c)

c. null

d)

d. An empty string

10.

What is the result of the following code?

const x = 10; 

x = 20; 

console.log(x);

a)

a.    20

b)

b. 10

c)

c. Throws an error

d)

d. undefined

11.

What is the difference between null and undefined?



a)

a. null represents an absence of value, while undefined means a variable is declared but not assigned.

b)

b. Both are identical.

c)

c. null is an object, but undefined is a string.

d)

d. null means not initialized, undefined is a mistake.

12.

   What is the result of typeof null and typeof undefined?


a)

a. "null" and "undefined"

b)

b. "object" and "undefined"

c)

c. "undefined" and "null"

d)

d. Throws an error

13.

  What is the type of NaN?

a)

a. "undefined"

b)


b. "number"

c)


c. "NaN"

d)


d. Throws an error

14.

What is the purpose of the isNaN() function?

a)


a. Check if a value is a number

b)


b. Check if a value is not a number

c)


c. Check if a string is valid

d)


d. None of the above

15.

What is the result of parseInt("20.9")?

a)


a. 20.9

b)


b. 20

c)


c. NaN

d)


d. undefined

16.

What is the return value of Math.floor(4.7)?

a)


a. 5

b)


b. 4

c)


c. 4.7

d)


d. NaN

17.

What is the result of String(123) + 456?

a)


a. 579

b)


b. "123456"

c)


c. 123456

d)


d. Throws an error

18.

Which command returns the current time?

a)
b)


b. new Date().getTime()

c)


c. Both of the above

d)


d. None of the above

19.

What is the result of the following code?

let str = "Hello";

console.log(str.length);

a)

a. 4

b)


b. 5

c)


c. undefined

d)


d. Throws an error

20.

Which method is used to check if a string starts with a specific character?

a)


a. startsWith()

b)


b. includes()

c)


c. indexOf()

d)


d. substring()

21.

  What is the result of "JavaScript".toUpperCase()?

a)


a. "javascript"

b)


b. "JAVASCRIPT"

c)


c. "JavaScript"

d)


d. Throws an error

22.

Which command is used to slice a string from position 2 to 5?

a)


a. str.substring(2, 5)

b)


b. str.slice(2, 5)

c)


c. Both of the above

d)


d. None of the above

23.

Which method returns the first occurrence position of a substring?

a)


a. lastIndexOf()

b)


b. indexOf()

c)


c. find()

d)


d. search()

24.

What is the result of Number("100") + 50 + true?

a)


a. 150 + 1

b)


b. "10051"

c)


c. NaN

d)


d. Throws an error

25.

Which command converts a number to a string?

a)


a. toString()

b)


b. parseInt()

c)


c. Number()

d)


d. join()

26.

What is the result of Math.round(4.5)?

a)


a. 4

b)


b. 5

c)


c. 4.5

d)


d. NaN

27.

Which function returns a random number between 0 and 1?

a)


a. Math.random()

b)


b. Math.floor()

c)


c. Math.abs()

d)


d. Math.ceil()

28.

What is the result of Math.max(3, 5, 1)?

a)


a. 3

b)


b. 5

c)


c. 1

d)


d. undefined

29.

Which method adds an element to the end of an array?

a)


a. push()

b)


b. pop()

c)

c. shift()

d)


d. unshift()

30.

Does the map() method mutate the original array in JavaScript?

a)

a) Yes, it modifies the original array by applying the callback function.

b)


b) No, it creates a new array and does not modify the original array.

c)


c) It only modifies the original array if the callback function returns a value.

d)


d) It mutates the original array but only for objects, not primitive values.

31.

Which method returns an array that is a concatenation of two arrays?

a)


a. join()

b)


b. concat()

c)


c. splice()

d)


d. slice()

32.

What is the result of ["x", "y", "z"].indexOf("y")?

a)


a. 0

b)


b. 1

c)


c. 2

d)


d. -1

33.

How do you select an HTML element by its ID?

a)


a. document.getElementById()

b)


b. document.querySelector()

c)


c. document.getElementsByClassName()

d)


d. Both a and b

34.

Which function adds a click event to an element?

b)


b. element.addEventListener("click", ...)

c)


c. element.onClick()

d)


d. element.attachEvent()

35.

Which command creates a new HTML element?

a)


a. document.createElement()

b)


b. document.append()

c)


c. document.newElement()

d)


d. document.createNode()

36.

Which keyword is used to declare a function in JavaScript?

a)


a. function

b)


b. def

c)


c. func

d)


d. None of the above

37.

What is the result of:

javascript

Sao chép mã

let add = (a, b) => a + b; 

console.log(add(3, 7));

a)

a. 10

b)


b. 37

c)


c. Error

d)


d. None of the above

38.

How to run a piece of code only once after a specific time interval in

a)

a) setInterval()

b)


b) setTimeout()

c)


c) clearTimeout()

d)


d) clearInterval()

39.

What is the result of:

javascript

Sao chép mã

const arr = [1, 2, 3]; 

const result = arr.map(num => num * 2); 

console.log(result);

a)

a. [2, 4, 6]

b)


b. [1, 2, 3]

c)


c. [2, 2, 2]

d)


d. Error

40.

What is the correct method to run a piece of code after a specific time interval in JavaScript?

a)

a) setInterval()

b)


b) setTimeout()

c)


c) clearTimeout()

d)


d) runAfterTime()

41.

Which keyword is used to copy all properties of one object into another?

a)


a. Object.assign()

b)


b. Object.copy()

c)


c. Object.create()

d)


d. Object.merge()

42.

Which property returns the keys of an object?

a)


a. Object.keys()

b)


b. Object.values()

c)


c. Object.entries()

d)


d. None of the above

43.

Which method prevents modification of an object?

a)


a. Object.freeze()

b)


b. Object.lock()

c)


c. Object.seal()

d)


d. None of the above

44.

What is the result of delete obj.key?

a)


a. Deletes the key and its corresponding value

b)


b. Returns undefined

c)


c. Error

d)


d. None of the above

45.

What is the result of the following code?

const users = { 

    name: "hune", 

    age: 19, 

    phone: 0123456789, 

    social: { 

      ticktok: "hune1209", 

      instagram: "hune1209", 

      facebook: "hune1209" 

    } 

}; 

users.phone = "1"; 

console.log(users);

a)

a. Error “Uncaught TypeError: Assignment to constant variable.”

b)

b. undefined

c)

c. {"name": "hune",

"age": 19,
"phone": "1",
"social":

{"ticktok": "hune1209",
"instagram": "hune1209",
"facebook": "hune1209"}
}

d)

c. {"name": "hune",

"age": 19,
"phone": "0123456789",
"social":

{"ticktok": "hune1209",
"instagram": "hune1209",
"facebook": "hune1209"}
}

46.

Which method checks if all elements in the array meet a condition?

a)


a. filter()

b)


b. map()

c)


c. forEach()

d)


d. reduce()

47.

What is the result of:

const a = [1, 2, 3, 4, 5]; 

const b = ["6", 7, 8, 9, 10]; 

const c = [...a, ...b]; 

console.log(c);

a)

a. [1, 2, 3, 4, 5, "6", 7, 8, 9, 10]

b)


b. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

c)


c. []

d)


d. undefined

48.

Which method pick the first letter of an string?

a)



a. slice(0,1)

b)



b. chatAt(0)

c)


c. both a and b

d)


d. none of answer

49.

What is the result of the following code?

const cart = [ 

  { product: "Apple", quantity: 2, price: 3 }, 

  { product: "Banana", quantity: 5, price: 1 }, 

  { product: "Cherry", quantity: 7, price: 2 } 

]; 

const totalQuantity = cart.reduce((total, item) => total + item.quantity, 0); 

console.log(`Total product quantity: ${totalQuantity}`);

a)

a. 14

b)


b. 16

c)


c. 3

d)


d. Error

50.

Which command returns an array with only unique values from an original array?

a)


a. new Set([...arr])

b)


b. Array.unique()

c)


c. arr.filter()

d)


d. None of the above