100% found this document useful (1 vote)
4K views13 pages

JavaScript Quiz: 25 Key Questions

The document contains 25 JavaScript quiz questions testing knowledge of JavaScript concepts like data types, operators, functions, objects, and more. It includes the question, possible answers, and the correct answer explanation. The questions cover topics such as variable declaration, JSON parsing, promises, arrow functions, classes, modules and more. Taking this quiz can help assess understanding of JavaScript fundamentals.

Uploaded by

pgkalex455
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views13 pages

JavaScript Quiz: 25 Key Questions

The document contains 25 JavaScript quiz questions testing knowledge of JavaScript concepts like data types, operators, functions, objects, and more. It includes the question, possible answers, and the correct answer explanation. The questions cover topics such as variable declaration, JSON parsing, promises, arrow functions, classes, modules and more. Taking this quiz can help assess understanding of JavaScript fundamentals.

Uploaded by

pgkalex455
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • JavaScript Quiz Introduction
  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5 through 7
  • Question 8 through 9
  • Question 10 through 11
  • Question 12 through 13
  • Question 16 through 17
  • Question 14 through 15
  • Question 18 through 20
  • Question 21 through 23
  • Question 24 through 25

25 JavaScript

QUIZ Questions
Test your Knowledge!

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


Q: Which method can be used to convert JSON data to a JavaScript object? 2
Q: What does the map() method do? 3
Q: What will [Link](typeof null) output? 3
Q: How do you create a new Promise in JavaScript? 4
Q: Which of the following is not a valid way to declare a variable in JavaScript? 4
Q: What is the purpose of the [Link]() method? 4
Q: Which operator is used to check both value and type? 5
Q: What will [Link](0.1 + 0.2 == 0.3) output? 5
Q: What is the purpose of the splice() method in arrays? 6
Q: How can you get the number of milliseconds elapsed since January 1, 1970? 6
Q: What does the this keyword refer to inside an arrow function? 7
Q: What are higher-order functions in JavaScript? 7
Q: What is event delegation in JavaScript? 8
Q: Which HTML element is used to embed JavaScript? 8
Q: What is the main use of the async keyword in JavaScript? 8
Q: What is the output of [Link]("2" + 2 * "2")? 9
Q: How can you stop the execution of a setInterval timer? 9
Q: What is the correct way to create an object in JavaScript? 10
Q: What will be the result of [Link](!!"false")? 10

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
1
Q: How do you find the minimum of two numbers x and y in JavaScript? 11
Q: Which statement creates a new function in JavaScript? 11
Q: What is the use of the finally statement in a try-catch block? 11
Q: How do you declare a static method in a JavaScript class? 12
Q: What is the correct syntax for importing a module in ES6? 12

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. [Link]()
2. [Link]()
3. [Link]()
4. [Link]()

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
2
A: 1. [Link]()

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 [Link](typeof null) output?

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

Question 5

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
3
Q: How do you create a new Promise in JavaScript?

1. new Promise()
2. [Link]()
3. [Link]()
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 [Link]() method?

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
4
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 [Link](0.1 + 0.2 == 0.3) output?

1. true
2. false

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
5
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. [Link]()
2. [Link]()
3. new Date().getTime()
4. new Date().milliseconds()
A: 2. [Link]()

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
6
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

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
7
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.

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
8
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 [Link]("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()

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
9
Question 19

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


JavaScript?

1. var obj = new Object();


2. var obj = [Link]();
3. var obj = {};
4. Both 1 and 3.
A: 4. Both 1 and 3.

Question 20

Q: What will be the result of [Link](!!"false")?

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

Question 21

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
10
Q: How do you find the minimum of two numbers x and y
in JavaScript?

1. min(x, y)
2. [Link](x, y)
3. [Link](x, y)
4. [Link](y)
A: 2. [Link](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?

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
11
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. [Link] 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 "[Link]";
2. require("[Link]");
3. include myModule from "[Link]";

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
12
4. load "[Link]";
A: 1. import myModule from "[Link]";

Learn more about JavaScript with Examples and Source Code Laurence Svekis
Courses [Link]
13

Common questions

Powered by AI

Higher-order functions in JavaScript are functions that operate on other functions by either taking them as arguments or returning them. They contribute to the functional programming paradigm by promoting the use of functions as first-class citizens, enabling more abstract and reusable code. This facilitates concepts like function composition and higher-level abstractions in application design, leading to more modular and maintainable code structures.

The 'async' keyword in JavaScript marks a function as asynchronous, allowing it to return a promise. Its role in simplifying asynchronous operations is crucial as it provides a cleaner and more readable syntax for handling promises through 'await'. This shifts the execution flow from traditional callback patterns to a more linear one, resembling synchronous code, thus enhancing readability and maintainability. It helps developers avoid 'callback hell' by enabling clear, sequential execution of operations that rely on asynchronous data fetching or other non-blocking activities.

The 'map' method enhances functional programming in JavaScript by applying a transformation function to each element of an array and returning a new array with the results, thus leaving the original array unchanged. This practice promotes data immutability, a key tenet of functional programming, which helps in maintaining predictable state management and avoiding side effects, thus improving the reliability and testability of code.

In JavaScript, lexical scoping affects the behavior of the 'this' keyword in arrow functions by binding it to the scope in which the arrow function is defined, not where it is invoked. Unlike traditional functions, arrow functions do not have their own 'this' context; instead, they inherit the 'this' value from their parent scope. This makes arrow functions particularly useful in class methods or callbacks, where developers want to preserve context without explicitly using `bind()`. Understanding this distinction is crucial for correct function behavior within certain scopes.

JSON.parse() is used in web applications to convert a JSON string received from a server into a JavaScript object, facilitating data manipulation. For example, after fetching data via an XMLHttpRequest or Fetch API, a developer can parse the response body: `let data = JSON.parse(responseBody);`. This operation is critical in applications that work with API calls, as it allows developers to access and process server data seamlessly using standard JavaScript syntax and operations.

The 'reduce' method in JavaScript executes a reducer function on each element of the array, accumulating the result into a single output value. It is highly versatile for performing complex data transformations such as aggregating array values, counting instances, or flattening arrays. For example, to find the total sales from an array of transaction objects, reduce could iterate through all transactions, summing up the 'amount' property of each object: `transactions.reduce((total, transaction) => total + transaction.amount, 0)`. This example highlights its ability to distill an array of objects into a singular value like total sales.

JavaScript's arithmetic operation '0.1 + 0.2 == 0.3' evaluates to false due to floating-point precision limitations. Internally, numbers are represented in a binary fraction format, leading to small rounding errors in decimal operations. To address this, developers can use functions like `Number.EPSILON` for comparison or convert numbers to a fixed precision string for accurate equality checks. These strategies mitigate precision errors and ensure correct logical evaluations in conditions involving decimals.

Event delegation in JavaScript involves handling events at a parent element rather than directly on the individual elements that trigger the events. By using a single event listener on a parent element, event delegation can significantly improve performance, especially in dynamic DOM structures where elements may be added or removed. This reduces memory consumption and increases efficiency by minimizing the number of event listeners that need to be attached to the DOM, as the parent element can handle any events bubbled up from its children.

'===' is used in JavaScript for strict equality checks, comparing both value and type, unlike '==' which performs type coercion where necessary. Using '===' helps prevent common logic errors that arise from unexpected type conversions, such as '5 == "5"' evaluating to true, which could cause flaws in condition checks and application logic. Adopting a habit of using '===' ensures more predictable and error-proof code, upholding data integrity throughout applications.

The 'typeof' operator returning "object" for the value 'null' in JavaScript is a known language quirk stemming from its early implementation. This misclassification can lead to errors when checking for null values using 'typeof'. Developers should handle this by explicitly checking for 'null' using strict equality operators, i.e., `value === null`, to accurately detect null values in conditional statements. Understanding this quirk is critical for debugging and writing robust code that correctly distinguishes between different data types.

25 JavaScript
QUIZ Questions
Test your Knowledge!
Q: What is the output of "10" + 20 in JavaScript?
2
Q: Which method can be
Q: How do you find the minimum of two numbers x and y in JavaScript?
11
Q: Which statement creates a new function in JavaScri
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.
Q: How do you create a new Promise in JavaScript?
1. new Promise()
2. Promise.create()
3. Promise.new()
4. new Async()
A: 1.
1. To execute a reducer function on each element of the array, resulting in a
single output value.
2. To check if all element
3. TypeError
4. undefined
A: 2. false
Question 10
Q: What is the purpose of the splice() method in arrays?
1. To connect two
Question 12
Q: What does the this keyword refer to inside an arrow
function?
1. The arrow function itself
2. The object that
Q: What is event delegation in JavaScript?
1. Triggering an event on multiple elements individually.
2. Handling an event at
2. To mark a function as asynchronous.
3. To speed up code execution.
4. To avoid using callbacks.
A: 2. To mark a function a
Question 19
Q: What is the correct way to create an object in
JavaScript?
1. var obj = new Object();
2. var obj = Object.crea

You might also like