25 JavaScript QUIZ Questions Test your Knowledge!

25 JavaScript QUIZ Questions Test your Knowledge!

Learn more about JavaScript Download PDF Guide at https://basescripts.com/25-javascript-quiz-questions-test-your-knowledge

Question 1

Q: What is the output of "10" + 20 in JavaScript?

  1. 30
  2. "1020"
  3. TypeError
  4. undefined

A: 2. "1020"

Question 2

Q: Which method can be used to convert JSON data to a JavaScript object?

  1. JSON.parse()
  2. JSON.stringify()
  3. JSON.toObject()
  4. JSON.toJavaScript()

A: 1. JSON.parse()

Question 3

Q: What does the map() method do?

  1. Modifies each item in an array and returns a new array.
  2. Returns the first element passing a test.
  3. Executes a function for each array element.
  4. Filters elements based on a test and returns a new array.

A: 1. Modifies each item in an array and returns a new array.

Question 4

Q: What will console.log(typeof null) output?

  1. "null"
  2. "object"
  3. "undefined"
  4. "number"

A: 2. "object"

Question 5

Q: How do you create a new Promise in JavaScript?

  1. new Promise()
  2. Promise.create()
  3. Promise.new()
  4. new Async()

A: 1. new Promise()

Question 6

Q: Which of the following is not a valid way to declare a variable in JavaScript?

  1. let x = 1;
  2. const x = 1;
  3. var x = 1;
  4. int x = 1;

A: 4. int x = 1;

Question 7

Q: What is the purpose of the Array.reduce() method?

  1. To execute a reducer function on each element of the array, resulting in a single output value.
  2. To check if all elements in an array pass a test.
  3. To loop through an array.
  4. To reduce the size of an array by half.

A: 1. To execute a reducer function on each element of the array, resulting in a single output value.

Question 8

Q: Which operator is used to check both value and type?

  1. ==
  2. !=
  3. ===
  4. !==

A: 3. ===

Question 9

Q: What will console.log(0.1 + 0.2 == 0.3) output?

  1. true
  2. false
  3. TypeError
  4. undefined

A: 2. false

Question 10

Q: What is the purpose of the splice() method in arrays?

  1. To connect two arrays.
  2. To search for elements.
  3. To add/remove elements from an array.
  4. To slice a portion of the array.

A: 3. To add/remove elements from an array.

Question 11

Q: How can you get the number of milliseconds elapsed since January 1, 1970?

  1. Date.getMilliseconds()
  2. Date.now()
  3. new Date().getTime()
  4. new Date().milliseconds()

A: 2. Date.now()

Question 12

Q: What does the this keyword refer to inside an arrow function?

  1. The arrow function itself
  2. The object that called the function
  3. The global object
  4. The parent scope

A: 4. The parent scope

Question 13

Q: What are higher-order functions in JavaScript?

  1. Functions that operate on other functions.
  2. Functions that are written in uppercase.
  3. Asynchronous functions.
  4. Functions that return other functions.

A: 1. Functions that operate on other functions.

Question 14

Q: What is event delegation in JavaScript?

  1. Triggering an event on multiple elements individually.
  2. Handling an event at a parent element rather than the element itself.
  3. Delegating event handling to the browser.
  4. Scheduling events in the future.

A: 2. Handling an event at a parent element rather than the element itself.

Question 15

Q: Which HTML element is used to embed JavaScript?

  1. <javascript>
  2. <js>
  3. <script>
  4. <code>

A: 3. <script>

Question 16

Q: What is the main use of the async keyword in JavaScript?

  1. To run a function in a separate thread.
  2. To mark a function as asynchronous.
  3. To speed up code execution.
  4. To avoid using callbacks.

A: 2. To mark a function as asynchronous.

Question 17

Q: What is the output of console.log("2" + 2 * "2")?

  1. 24
  2. 6
  3. "222"
  4. "42"

A: 4. "42"

Question 18

Q: How can you stop the execution of a setInterval timer?

  1. clearInterval()
  2. clearTimer()
  3. stopInterval()
  4. pauseInterval()

A: 1. clearInterval()

Question 19

Q: What is the correct way to create an object in JavaScript?

  1. var obj = new Object();
  2. var obj = Object.create();
  3. var obj = {};
  4. Both 1 and 3.

A: 4. Both 1 and 3.

Question 20

Q: What will be the result of console.log(!!"false")?

  1. true
  2. false
  3. "false"
  4. null

A: 1. true

Question 21

Q: How do you find the minimum of two numbers x and y in JavaScript?

  1. min(x, y)
  2. Math.min(x, y)
  3. Math.minimum(x, y)
  4. x.min(y)

A: 2. Math.min(x, y)

Question 22

Q: Which statement creates a new function in JavaScript?

  1. function myFunc() {}
  2. var myFunc = function() {};
  3. var myFunc = new Function();
  4. All of the above.

A: 4. All of the above.

Question 23

Q: What is the use of the finally statement in a try-catch block?

  1. To run code after a try block only if there are no errors.
  2. To execute code whether an exception is thrown or not.
  3. To finalize object cleanup.
  4. To run final checks.

A: 2. To execute code whether an exception is thrown or not.

Question 24

Q: How do you declare a static method in a JavaScript class?

  1. static methodName() {}
  2. methodName() static {}
  3. class.static methodName() {}
  4. method staticName() {}

A: 1. static methodName() {}

Question 25

Q: What is the correct syntax for importing a module in ES6?

  1. import myModule from "module.js";
  2. require("module.js");
  3. include myModule from "module.js";
  4. load "module.js";

A: 1. import myModule from "module.js";

要查看或添加评论,请登录

JavaScript Developer WorldWide的更多文章

社区洞察

其他会员也浏览了