Sharpen Your JavaScript Skills with These Multiple-Choice Questions
download PDF guide https://basescripts.com/sharpen-your-javascript-skills-with-these-multiple-choice-questions
JavaScript Questions
Test your knowledge
1. What is JavaScript?
a) A programming language
b) A database management system
c) A markup language
d) An operating system
Answer: a) A programming language
2. What is the purpose of the "typeof" operator in JavaScript?
a) To check the data type of a variable
b) To create a new variable
c) To concatenate strings
d) To define a function
Answer: a) To check the data type of a variable
3. How do you declare a variable in JavaScript?
a) var
b) variable
c) v
d) let
Answer: a) var
4. What does the "===" operator in JavaScript do?
a) Compares values for equality without type coercion
b) Assigns a value to a variable
c) Checks if a variable is defined
d) Performs bitwise XOR operation
Answer: a) Compares values for equality without type coercion
5. What is the result of the expression "5 + '5'"?
a) 10
b) 55
c) 25
d) "55"
Answer: d) "55"
6. Which keyword is used to define a function in JavaScript?
a) function
b) def
c) func
d) define
Answer: a) function
7. What is the purpose of the "return" statement in a function?
a) To print a value to the console
b) To exit the function and return a value
c) To declare a variable
d) To concatenate strings
Answer: b) To exit the function and return a value
8. How do you comment a single-line in JavaScript?
a) //
b) /* */
c) #
d) ---
Answer: a) //
9. What is the difference between "null" and "undefined" in JavaScript?
a) They are the same
b) "null" represents the absence of a value, while "undefined" is a variable that has been declared but not assigned a value
c) "undefined" represents the absence of a value, while "null" is a variable that has been declared but not assigned a value
d) "null" and "undefined" are both used to represent an empty string
Answer: b) "null" represents the absence of a value, while "undefined" is a variable that has been declared but not assigned a value
10. What does the "this" keyword refer to in JavaScript?
a) The current function
b) The global object
c) The parent object
d) The variable being passed to a function
Answer: b) The global object
11. How do you check if a variable is an array in JavaScript?
a) isArray()
b) isObject()
c) typeofArray()
d) arrayCheck()
Answer: a) isArray()
12. What does the "map" function do in JavaScript?
a) Iterates over the elements of an array and applies a function to each element
b) Creates a new array with all elements that pass a test
c) Filters the elements of an array based on a condition
d) Reduces the array to a single value
Answer: a) Iterates over the elements of an array and applies a function to each element
13. Which keyword is used to prevent a variable from being modified?
a) freeze
b) const
c) lock
d) protect
Answer: b) const
14. What is a closure in JavaScript?
a) A way to close a function
b) A function inside another function that has access to the outer function's variables
c) A type of loop
d) A variable declared within a function
Answer: b) A function inside another function that has access to the outer function's variables
15. What is the purpose of the "setTimeout" function in JavaScript?
a) Delays the execution of a function by a specified number of milliseconds
b) Repeats the execution of a function at a set interval
c) Halts the execution of a function
d) Sets the time zone of the script
Answer: a) Delays the execution of a function by a specified number of milliseconds
16. What does the "JSON" acronym stand for in JavaScript?
a) JavaScript Object Notation
b) Java Syntax Object Notation
c) Just Simple Object Naming
d) JavaScript Oriented Notation
Answer: a) JavaScript Object Notation
17. How do you handle errors in JavaScript?
a) try-catch
b) error()
c) catch-throw
d) handle-error
Answer: a) try-catch
18. What does the "isNaN" function do?
a) Checks if a value is not a number
b) Checks if a value is a number
c) Converts a string to a number
d) Rounds a number to the nearest integer
Answer: a) Checks if a value is not a number
19. What is the purpose of the "push" method in JavaScript?
a) Adds elements to the end of an array
b) Removes elements from the beginning of an array
c) Adds elements to the beginning of an array
d) Removes elements from the end of an array
Answer: a) Adds elements to the end of an array
20. How do you create a new object in JavaScript?
a) new Object()
b) createObject()
c) {}
d) Object.create()
Answer: c) {}
21. What is the difference between "let," "const," and "var" for variable declaration?
a) They are interchangeable
b) "let" is block-scoped, "const" is block-scoped and cannot be reassigned, and "var" is function-scoped
c) "let" is block-scoped, "const" is function-scoped, and "var" is block-scoped
d) "let" is function-scoped, "const" is block-scoped, and "var" is function-scoped
Answer: b) "let" is block-scoped, "const" is block-scoped and cannot be reassigned, and "var" is function-scoped
22. What is the purpose of the "splice" method in JavaScript?
a) Removes elements from an array and returns the removed elements
b) Adds elements to an array and returns the new array length
领英推荐
c) Concatenates two arrays
d) Reverses the elements of an array
Answer: a) Removes elements from an array and returns the removed elements
23. How do you convert a string to a number in JavaScript?
a) parseInt()
b) toNumber()
c) Number()
d) stringToNumber()
Answer: c) Number()
24. What is the purpose of the "querySelector" method in JavaScript?
a) Selects the first element that matches a specified CSS selector
b) Selects all elements that match a specified CSS selector
c) Selects the last element that matches a specified CSS selector
d) Selects an element by its ID
Answer: a) Selects the first element that matches a specified CSS selector
25. What is the difference between "null" and "undefined"?
a) They are the same
b) "null" represents the absence of a value, while "undefined" is a variable that has been declared but not assigned a value
c) "undefined" represents the absence of a value, while "null" is a variable that has been declared but not assigned a value
d) "null" and "undefined" are both used to represent an empty string
Answer: b) "null" represents the absence of a value, while "undefined" is a variable that has been declared but not assigned a value
26. What does the "bind" method do in JavaScript?
a) Creates a new array with the results of calling a function for every array element
b) Binds a function to a particular object, ensuring that "this" refers to the specified object
c) Combines two arrays into one
d) Creates a copy of an array with the elements reversed
Answer: b) Binds a function to a particular object, ensuring that "this" refers to the specified object
27. What is an IIFE (Immediately Invoked Function Expression) in JavaScript?
a) A function that is automatically invoked when the script loads
b) A function that is executed only when called explicitly
c) A function that is defined inside another function
d) A function that runs forever
Answer: a) A function that is automatically invoked when the script loads
28. What is the purpose of the "Promise" object in JavaScript?
a) To handle asynchronous operations and represent a value that might be available now, or in the future, or never
b) To create a new object
c) To check if a variable is defined
d) To concatenate strings
Answer: a) To handle asynchronous operations and represent a value that might be available now, or in the future, or never
29. What is the purpose of the "filter" method in JavaScript?
a) Iterates over the elements of an array and applies a function to each element
b) Creates a new array with all elements that pass a test
c) Combines two arrays into one
d) Reduces the array to a single value
Answer: b) Creates a new array with all elements that pass a test
30. How do you declare a constant variable in JavaScript?
a) const
b) let
c) var
d) constant
Answer: a) const
31. What does the "addEventListener" method do in JavaScript?
a) Adds an event listener to a DOM element
b) Removes an event listener from a DOM element
c) Appends a new child element to a parent element
d) Adds a new event to the event queue
Answer: a) Adds an event listener to a DOM element
32. What is the purpose of the "charAt" method in JavaScript?
a) Returns the character at a specified index in a string
b) Concatenates two strings
c) Converts a string to uppercase
d) Returns the length of a string
Answer: a) Returns the character at a specified index in a string
33. How do you reverse the order of elements in an array?
a) reverse()
b) flip()
c) invert()
d) backward()
Answer: a) reverse()
34. What is the purpose of the "event.preventDefault()" method in JavaScript?
a) Stops the propagation of an event to parent elements
b) Prevents the default action associated with an event from occurring
c) Captures all events in the document
d) Removes an event listener from a DOM element
Answer: b) Prevents the default action associated with an event from occurring
35. What is the purpose of the "querySelectorAll" method in JavaScript?
a) Selects the first element that matches a specified CSS selector
b) Selects all elements that match a specified CSS selector
c) Selects the last element that matches a specified CSS selector
d) Selects an element by its ID
Answer: b) Selects all elements that match a specified CSS selector
36. What is the purpose of the "concat" method in JavaScript?
a) Combines two arrays into one
b) Creates a new array with the results of calling a function for every array element
c) Adds elements to the end of an array
d) Removes elements from an array
Answer: a) Combines two arrays into one
37. What is the output of the following code?
javascript
Copy code
console.log(1 + '1' - 1);
a) 10
b) 11
c) 01
d) "11"
Answer: b) 11
38. What is the purpose of the "slice" method in JavaScript?
a) Returns a section of a string
b) Removes elements from an array and returns the removed elements
c) Adds elements to the end of an array
d) Reverses the elements of an array
Answer: a) Returns a section of a string
39. What does the "toLowerCase" method do in JavaScript?
a) Converts a string to lowercase
b) Converts a string to uppercase
c) Removes leading and trailing whitespaces from a string
d) Splits a string into an array of substrings
Answer: a) Converts a string to lowercase
40. What is the purpose of the "shift" method in JavaScript?
a) Adds elements to the end of an array
b) Removes elements from the beginning of an array
c) Adds elements to the beginning of an array
d) Removes elements from the end of an array
Answer: b) Removes elements from the beginning of an array
41. How do you convert a number to a string in JavaScript?
a) toString()
b) toText()
c) stringify()
d) numberToString()
Answer: a) toString()
42. What is the purpose of the "find" method in JavaScript?
a) Iterates over the elements of an array and applies a function to each element
b) Creates a new array with all elements that pass a test
c) Returns the first element in an array that satisfies a provided testing function
d) Reduces the array to a single value
Answer: c) Returns the first element in an array that satisfies a provided testing function
43. What is the purpose of the "includes" method in JavaScript?
a) Checks if a value is not a number
b) Checks if a value is a number
c) Checks if an array includes a certain element
d) Checks if a string includes a certain substring
Answer: c) Checks if an array includes a certain element
--
6 个月I think the answer of the question no. 37 will be 10.
Attended Usmania uni
9 个月Marvel