Advertisement
cornford-michael

js quiz

Sep 8th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. 👨‍💻 Whether you’re a beginner looking to learn or a seasoned pro wanting to test your skills, this quiz has something for everyone!
  4.  
  5. Test Your Knowledge Today!
  6. Question 1 What does let keyword in JavaScript signify?
  7.  
  8. A. A constant variable
  9.  
  10. B. A block-scoped variable
  11.  
  12. C. A global variable
  13.  
  14. D. A function-scoped variable
  15.  
  16. Answer: B. A block-scoped variable
  17.  
  18. Explanation: The let keyword allows you to declare variables that are limited in scope to the block, statement, or expression in which they are used. Unlike var, which declares a function-scoped or globally-scoped variable, let ensures that the variable is only accessible within its declared context.
  19.  
  20. if (true) {
  21.  
  22.  let a = 40;
  23.  
  24.  console.log(a); // outputs 40
  25.  
  26. }
  27.  
  28. console.log(a); // Uncaught ReferenceError: a is not defined
  29. Question 2 Which method converts a JSON string into a JavaScript object?
  30.  
  31. A. JSON.parse()
  32.  
  33. B. JSON.stringify()
  34.  
  35. C. Object.toJSON()
  36.  
  37. D. String.parseJSON()
  38.  
  39. Answer: A. JSON.parse()
  40.  
  41. Explanation: JSON.parse() is used to parse a JSON string and construct the JavaScript value or object described by the string.
  42.  
  43. const jsonString ={“name”: “John”, “age”: 30};
  44.  
  45. const obj = JSON.parse(jsonString);
  46.  
  47. console.log(obj.name); // John
  48. Question 3 Which operator is used to check both the value and the type?
  49.  
  50. A. ==
  51.  
  52. B. ===
  53.  
  54. C. =
  55.  
  56. D. !=
  57.  
  58. Answer: B. ===
  59.  
  60. Explanation: The === operator is known as the strict equality operator and it compares both the value and the type of two operands. In contrast, the == operator only compares the values, performing type coercion if necessary.
  61.  
  62. console.log(1 ===1); // false
  63.  
  64. console.log(1 ==1); // true
  65. Question 4 What will be the output of the following code?
  66.  
  67. console.log(typeof null);
  68.  
  69. A. “null
  70.  
  71. B. “undefined
  72.  
  73. C. “object”
  74.  
  75. D. “number”
  76.  
  77. Answer: C. “object”
  78.  
  79. Explanation: In JavaScript, typeof null returns “object”. This is actually a bug in the language and one of its peculiarities, as null is not really an object.
  80. Question 5 What is a closure in JavaScript?
  81.  
  82. A. A function along with its lexical environment.
  83.  
  84. B. An inner function that has access to the outer function’s variables.
  85.  
  86. C. Both A and B.
  87.  
  88. D. A syntax error.
  89.  
  90. Answer: C. Both A and B.
  91.  
  92. Explanation: A closure is a function combined with its lexical environment (the environment in which it was declared). This means it has access to outer function’s variables even after the outer function has returned.
  93.  
  94. function outerFunction() {
  95.  
  96.  let outerVariable = 100;
  97.  
  98.  function innerFunction() {
  99.  
  100.  console.log(outerVariable);
  101.  
  102.  }
  103.  
  104.  return innerFunction;
  105.  
  106. }
  107.  
  108. const inner = outerFunction();
  109.  
  110. inner(); // Outputs: 100
  111. Question 6 Which of the following is not a reserved word in JavaScript?
  112.  
  113. A. interface
  114.  
  115. B. throws
  116.  
  117. C. program
  118.  
  119. D. short
  120.  
  121. Answer: C. program
  122.  
  123. Explanation: In JavaScript, interface, throws, and short are reserved words, but program is not. Reserved words have a specific meaning to the language or are reserved for future use.
  124. Question 7 What is the purpose of the Array.prototype.map() method?
  125.  
  126. A. To execute a function on each element in the array.
  127.  
  128. B. To modify each element in the array and create a new array.
  129.  
  130. C. To combine all elements of an array into a single value.
  131.  
  132. D. To check if at least one element in the array passes a test.
  133.  
  134. Answer: B. To modify each element in the array and create a new array.
  135.  
  136. Explanation: Array.prototype.map() creates a new array populated with the results of calling a provided function on every element in the calling array.
  137.  
  138. const numbers = [1, 2, 3];
  139.  
  140. const doubled = numbers.map(number => number * 2);
  141.  
  142. console.log(doubled); // [2, 4, 6]
  143. Question 8 What is the use of the bind method in JavaScript?
  144.  
  145. A. To bind the value of this in a method to an object.
  146.  
  147. B. To combine two strings.
  148.  
  149. C. To link a JavaScript file to an HTML document.
  150.  
  151. D. To repeat a string multiple times.
  152.  
  153. Answer: A. To bind the value of this in a method to an object.
  154.  
  155. Explanation: The bind method creates a new function that, when called, has its this keyword set to the provided value.
  156.  
  157. const person = {
  158.  
  159.  name: ‘John’,
  160.  
  161.  greet: function() { console.log(`Hello, ${this.name}`); }
  162.  
  163. };
  164.  
  165. const greet = person.greet.bind({name: ‘Jane’});
  166.  
  167. greet(); // Hello, Jane
  168. Question 9 Which statement is true about JavaScript’s arrow functions?
  169.  
  170. A. They have their own this context.
  171.  
  172. B. They cannot return values.
  173.  
  174. C. They are shorter syntax for writing function expressions.
  175.  
  176. D. They can be used as constructors.
  177.  
  178. Answer: C. They are shorter syntax for writing function expressions.
  179.  
  180. Explanation: Arrow functions provide a concise syntax for writing function expressions. They don’t have their own bindings to this, arguments, super, or new.target, and are not suitable for use as constructors.
  181.  
  182. const add = (a, b) => a + b;
  183.  
  184. console.log(add(2, 3)); // 5
  185. Question 10 What does the unshift method do in an array?
  186.  
  187. A. Adds new elements to the end of an array.
  188.  
  189. B. Removes the first element from an array.
  190.  
  191. C. Adds new elements to the beginning of an array.
  192.  
  193. D. Removes the last element from an array.
  194.  
  195. Answer: C. Adds new elements to the beginning of an array.
  196.  
  197. Explanation: The unshift method adds one or more elements to the beginning of an array and returns the new length of the array.
  198.  
  199. const array = [1, 2, 3];
  200.  
  201. array.unshift(0);
  202.  
  203. console.log(array); // [0, 1, 2, 3]
  204. Question 11 What will the following code output?
  205.  
  206. console.log(0.1 + 0.2 === 0.3);
  207.  
  208. A. true
  209. B. false
  210. C. TypeError
  211. D. undefined
  212.  
  213. Answer: B. false
  214.  
  215. Explanation: This is a classic floating point math problem in many programming languages. The result of 0.1 + 0.2 is not exactly 0.3 due to the way numbers are represented in JavaScript (IEEE 754 standard for floating-point arithmetic).
  216. Question 12 What is event delegation in JavaScript?
  217.  
  218. A. A way to handle events on parent elements rather than individual child elements.
  219.  
  220. B. A method to delegate event handling to a different element than the one that received the event.
  221.  
  222. C. A technique to speed up event handling.
  223.  
  224. D. A process to bind multiple events to a single event listener.
  225.  
  226. Answer: A. A way to handle events on parent elements rather than individual child elements.
  227.  
  228. Explanation: Event delegation is a technique where you use a single event listener on a parent element to manage all of its child events, taking advantage of event bubbling.
  229. Question 13 Which method is used to remove the last element from an array and returns that element?
  230.  
  231. A. pop()
  232. B. push()
  233. C. shift()
  234. D. unshift()
  235.  
  236. Answer: A. pop()
  237.  
  238. Explanation: pop() is used to remove the last element from an array and returns that element. This method changes the length of the array.
  239. Question 14 How can you get the total number of arguments passed to a function?
  240.  
  241. A. Using arguments.length
  242. B. Using arguments.size()
  243. C. Using this.length
  244. D. Using function.length
  245.  
  246. Answer: A. Using arguments.length
  247.  
  248. Explanation: The arguments object is an array-like object accessible inside functions that contains the values of the arguments passed to that function. arguments.length provides the number of arguments actually passed to the function.
  249. Question 15 Which statement about asynchronous requests in JavaScript is true?
  250.  
  251. A. They pause the execution of the script until the request is completed.
  252.  
  253. B. They allow the script to continue running while the request is being processed.
  254.  
  255. C. They are only possible using the XMLHttpRequest object.
  256.  
  257. D. They cannot handle HTTP GET requests.
  258.  
  259. Answer: B. They allow the script to continue running while the request is being processed.
  260.  
  261. Explanation: Asynchronous requests in JavaScript, such as those made using XMLHttpRequest or the fetch API, allow the script to continue running while the request is processed in the background.
  262. Question 16 What is the purpose of the Array.prototype.reduce() method?
  263.  
  264. A. To iterate over each element of an array.
  265.  
  266. B. To execute a reducer function on each element of the array, resulting in a single output value.
  267.  
  268. C. To filter out certain elements of an array.
  269.  
  270. D. To transform an array into a string.
  271.  
  272. Answer: B. To execute a reducer function on each element of the array, resulting in a single output value.
  273.  
  274. Explanation: The reduce() method executes a reducer function on each element of the array, resulting in a single output value. It is often used for accumulating values or concatenating strings.
  275. Question 17 In JavaScript, what will this code typeof NaN return?
  276.  
  277. A. “number”
  278. B. “NaN
  279. C. “undefined
  280. D. “object”
  281.  
  282. Answer: A. “number”
  283.  
  284. Explanation: NaN stands for “Not-a-Number” but is ironically of type “number” in JavaScript. This is one of the language’s quirks.
  285. Question 18 Which is a correct method to create a new object in JavaScript?
  286.  
  287. A. let obj = new Object();
  288. B. let obj = Object.create();
  289. C. let obj = {};
  290. D. All of the above
  291.  
  292. Answer: D. All of the above
  293.  
  294. Explanation: All three methods are correct ways to create a new object in JavaScript. new Object() and {} (object literal syntax) are more common, whereas Object.create() is used for more complex cases like setting the prototype chain.
  295. Question 19 How can you add a comment in a JavaScript file?
  296.  
  297. A. <!– This is a comment –>
  298. B. /* This is a comment */
  299. C. // This is a comment
  300. D. Both B and C
  301.  
  302. Answer: D. Both B and C
  303.  
  304. Explanation: In JavaScript, you can create a single-line comment using // and a multi-line comment using /* */.
  305. Question 20 Which method is used to randomly shuffle an array in JavaScript?
  306.  
  307. A. There is no built-in method, but it can be achieved by custom code.
  308.  
  309. B. Array.shuffle()
  310.  
  311. C. Math.random(array)
  312.  
  313. D. array.randomize()
  314.  
  315. Answer: A. There is no built-in method, but it can be achieved by custom code.
  316.  
  317. Explanation: JavaScript does not provide a built-in method to shuffle an array. However, you can achieve this by implementing a function, commonly using the Fisher-Yates (or Knuth) shuffle algorithm.
  318.  
  319. function shuffle(array) {
  320.  
  321.  for (let i = array.length1; i > 0; i–) {
  322.  
  323.  const j = Math.floor(Math.random() * (i + 1));
  324.  
  325.  [array[i], array[j]] = [array[j], array[i]];
  326.  
  327.  }
  328.  
  329.  return array;
  330.  
  331. }
  332. Question 21 What is the correct syntax for referring to an external script called script.js?
  333.  
  334. A. <script href=”script.js></script>
  335.  
  336. B. <script name=”script.js></script>
  337.  
  338. C. <script src=”script.js></script>
  339.  
  340. D. <script file=”script.js></script>
  341.  
  342. Answer: C. <script src=”script.js></script>
  343.  
  344. Explanation: The src attribute in the <script> tag is used to include external JavaScript files.
  345. Question 22 How do you write an if statement in JavaScript?
  346.  
  347. A. if (i == 5)
  348.  
  349. B. if i = 5 then
  350.  
  351. C. if i == 5 then
  352.  
  353. D. if (i = 5)
  354.  
  355. Answer: A. if (i == 5)
  356.  
  357. Explanation: The correct syntax for an if statement in JavaScript is if (condition).
  358. Question 23 How can you detect the client’s browser name in JavaScript?
  359.  
  360. A. navigator.appName
  361.  
  362. B. browser.name
  363.  
  364. C. client.browser
  365.  
  366. D. window.browserName
  367.  
  368. Answer: A. navigator.appName
  369.  
  370. Explanation: The navigator.appName property returns the name of the browser. However, detecting the browser using this method is generally discouraged in favor of feature detection.
  371. Question 24 Which JavaScript label catches all the values, except for the ones specified?
  372.  
  373. A. catch
  374.  
  375. B. label
  376.  
  377. C. default
  378.  
  379. D. except
  380.  
  381. Answer: C. default
  382.  
  383. Explanation: In a switch statement, the default keyword is used to specify the code to run if there is no case match.
  384. Question 25 What will the following code return: Boolean(10 > 9)
  385.  
  386. A. true
  387.  
  388. B. false
  389.  
  390. C. NaN
  391.  
  392. D. undefined
  393.  
  394. Answer: A. true
  395.  
  396. Explanation: Boolean(10 > 9) evaluates the expression 10 > 9, which is true.
  397. Question 26 Which event occurs when the user clicks on an HTML element?
  398.  
  399. A. onchange
  400.  
  401. B. onclick
  402.  
  403. C. onmouseover
  404.  
  405. D. onmouseclick
  406.  
  407. Answer: B. onclick
  408.  
  409. Explanation: The onclick event occurs when the user clicks on an element.
  410. Question 27 How do you declare a JavaScript variable?
  411.  
  412. A. v carName;
  413.  
  414. B. variable carName;
  415.  
  416. C. var carName;
  417.  
  418. D. let carName;
  419.  
  420. Answer: C. var carName; and D. let carName;
  421.  
  422. Explanation: Both var and let are used to declare a variable in JavaScript, but they have different scopes and hoisting behavior.
  423. Question 28 Which operator is used to assign a value to a variable?
  424.  
  425. A. *
  426.  
  427. B. –
  428.  
  429. C. =
  430.  
  431. D. x
  432.  
  433. Answer: C. =
  434.  
  435. Explanation: The = operator is used to assign values to variables in JavaScript.
  436. Question 29 What is the correct way to write a JavaScript array?
  437.  
  438. A. var colors = (1:”red”, 2:”green”, 3:”blue”)
  439.  
  440. B. var colors = “red”, “green”, “blue”
  441.  
  442. C. var colors = [“red”, “green”, “blue”]
  443.  
  444. D. var colors = 1 = (“red”), 2 = (“green”), 3 = (“blue”)
  445.  
  446. Answer: C. var colors = [“red”, “green”, “blue”]
  447.  
  448. Explanation: In JavaScript, an array is written as a list of values, each separated by a comma, and enclosed in square brackets.
  449. Question 30 What will the following code output?
  450.  
  451. console.log(typeof undefined === typeof NULL);
  452.  
  453. A. true
  454.  
  455. B. false
  456.  
  457. C. TypeError
  458.  
  459. D. undefined
  460.  
  461. Answer: B. false
  462.  
  463. Explanation: typeof undefined is ‘undefined, but typeof NULL will be ‘undefined’ only if NULL is not declared. Since JavaScript is case-sensitive, NULL is not the same as null. If NULL isn’t declared, this will result in a ReferenceError.
  464. Question 31 What is the method for rounding a number to the nearest integer in JavaScript?
  465.  
  466. A. Math.round()
  467.  
  468. B. Math.floor()
  469.  
  470. C. Math.ceil()
  471.  
  472. D. Number.round()
  473.  
  474. Answer: A. Math.round()
  475.  
  476. Explanation: Math.round() is used to round a number to the nearest integer.
  477. Question 32 Which of the following will check if a variable v is an array in JavaScript?
  478.  
  479. A. v.isArray()
  480.  
  481. B. Array.isArray(v)
  482.  
  483. C. v instanceof Array
  484.  
  485. D. Both B and C are correct
  486.  
  487. Answer: D. Both B and C are correct
  488.  
  489. Explanation: Array.isArray(v) is a standard method to check if v is an array. v instanceof Array also works but it might not be as reliable in all contexts, especially when dealing with different JavaScript contexts (like iframes).
  490. Question 33 How do you find the number with the highest value of x and y?
  491.  
  492. A. Math.ceil(x, y)
  493.  
  494. B. Math.max(x, y)
  495.  
  496. C. Math.top(x, y)
  497.  
  498. D. Math.highest(x, y)
  499.  
  500. Answer: B. Math.max(x, y)
  501.  
  502. Explanation: Math.max(x, y) returns the highest value among its arguments.
  503. Question 34 What will the following code output?
  504.  
  505. var x =1;
  506.  
  507. console.log(x === 1);
  508.  
  509. A. true
  510.  
  511. B. false
  512.  
  513. C. TypeError
  514.  
  515. D. undefined
  516.  
  517. Answer: B. false
  518.  
  519. Explanation: The === operator tests for both value and type equality. Since x is a string and 1 is a number, the comparison returns false.
  520. Question 35 What is the correct JavaScript syntax to change the content of the HTML element below?
  521.  
  522. <p id=”demo”>This is a demonstration.</p>
  523.  
  524. A. document.getElement(“p”).innerHTML = “Hello World!;
  525.  
  526. B. document.getElementById(“demo”).innerHTML = “Hello World!;
  527.  
  528. C. #demo.innerHTML = “Hello World!;
  529.  
  530. D. document.getElementByName(“p”).innerHTML = “Hello World!;
  531.  
  532. Answer: B. document.getElementById(“demo”).innerHTML = “Hello World!;
  533.  
  534. Explanation: document.getElementById(“demo”) is the correct method to select the element, and .innerHTML is used to change its content.
  535. Question 36 What is the correct syntax for adding comments in JavaScript?
  536.  
  537. A. <!– This is a comment –>
  538.  
  539. B. // This is a comment
  540.  
  541. C. /* This is a comment */
  542.  
  543. D. Both B and C
  544.  
  545. Answer: D. Both B and C
  546.  
  547. Explanation: In JavaScript, // is used for single-line comments and /* */ for multi-line comments.
  548. Question 37 How can a value be appended to an array in JavaScript?
  549.  
  550. A. arr[arr.length] = value;
  551.  
  552. B. arr.push(value);
  553.  
  554. C. arr += value;
  555.  
  556. D. Both A and B are correct
  557.  
  558. Answer: D. Both A and B are correct
  559.  
  560. Explanation: arr.push(value) adds a new element to the end of an array. Alternatively, setting arr[arr.length] = value; also appends the value to the end.
  561. Question 38 How do you create a function in JavaScript?
  562.  
  563. A. function myFunction()
  564.  
  565. B. function:myFunction()
  566.  
  567. C. function = myFunction()
  568.  
  569. D. new Function()
  570.  
  571. Answer: A. function myFunction()
  572.  
  573. Explanation: function myFunction() is the standard syntax for declaring a function in JavaScript.
  574. Question 39 What method is used to serialize an object into a JSON string in JavaScript?
  575.  
  576. A. JSON.stringify()
  577.  
  578. B. JSON.parse()
  579.  
  580. C. JSON.toObject()
  581.  
  582. D. Object.toJSON()
  583.  
  584. Answer: A. JSON.stringify()
  585.  
  586. Explanation: JSON.stringify() is used to convert an object into a JSON string.
  587. Question 40 What is the purpose of the this keyword in JavaScript?
  588.  
  589. A. It refers to the current object
  590.  
  591. B. It refers to the previously called object
  592.  
  593. C. It is a variable that stores data
  594.  
  595. D. It is a constant value
  596.  
  597. Answer: A. It refers to the current object
  598.  
  599. Explanation: In JavaScript, this is a reference to the current object the code is being written inside. Its value depends on where it is used.
  600. Question 41 Which of the following is true about the forEach method in JavaScript?
  601.  
  602. A. It changes the original array.
  603.  
  604. B. It returns a new array.
  605.  
  606. C. It can break out of the loop using a break statement.
  607.  
  608. D. It executes a provided function once for each array element.
  609.  
  610. Answer: D. It executes a provided function once for each array element.
  611.  
  612. Explanation: forEach() method executes a provided function once for each array element. Unlike map or filter, it does not return a new array and cannot be broken out of using break or return.
  613. Question 42 What does the following expression return?
  614.  
  615. typeof “x” === “string”
  616.  
  617. A. true
  618.  
  619. B. false
  620.  
  621. C. TypeError
  622.  
  623. D. undefined
  624.  
  625. Answer: A. true
  626.  
  627. Explanation: The typeof operator returns a string indicating the type of the unevaluated operand. In this case, “x” is a string, so typeof “x” returns “string”.
  628. Question 43 How do you create a Promise in JavaScript?
  629.  
  630. A. let promise = Promise(value);
  631.  
  632. B. let promise = new Promise((resolve, reject) => {});
  633.  
  634. C. let promise = Promise.create((resolve, reject) => {});
  635.  
  636. D. let promise = create Promise((resolve, reject) => {});
  637.  
  638. Answer: B. let promise = new Promise((resolve, reject) => {});
  639.  
  640. Explanation: Promises in JavaScript are created using the new Promise() constructor, which takes a function with resolve and reject arguments.
  641. Question 44 Which method is used to sort the elements of an array in place and returns the sorted array?
  642.  
  643. A. Array.sort()
  644.  
  645. B. Array.order()
  646.  
  647. C. Array.arrange()
  648.  
  649. D. Array.sequence()
  650.  
  651. Answer: A. Array.sort()
  652.  
  653. Explanation: Array.sort() is a method that sorts the elements of an array in place and returns the sorted array.
  654. Question 45 What is the output of the following code?
  655.  
  656. let x = 1;
  657.  
  658. function func() {
  659.  
  660.  console.log(x);
  661.  
  662.  let x = 2;
  663.  
  664. }
  665.  
  666. func();
  667.  
  668. A. 1
  669.  
  670. B. 2
  671.  
  672. C. undefined
  673.  
  674. D. ReferenceError
  675.  
  676. Answer: D. ReferenceError
  677.  
  678. Explanation: Due to JavaScript’s hoisting, the local variable x is hoisted to the top of the function, but it’s not initialized until let x = 2; is executed. Accessing x before the declaration results in a ReferenceError.
  679. Question 46 In JavaScript, what will the following return?
  680.  
  681. isNaN(“hello”)
  682.  
  683. A. true
  684.  
  685. B. false
  686.  
  687. C. TypeError
  688.  
  689. D. undefined
  690.  
  691. Answer: A. true
  692.  
  693. Explanation: The isNaN() function returns true if the value is NaN or not a number. The string “hello” is not a number, so the function returns true.
  694. Question 47 What does the !! (double exclamation point) operator do in JavaScript?
  695.  
  696. A. It inverts the boolean value of an expression twice.
  697.  
  698. B. It converts a value to a boolean with the same truthiness.
  699.  
  700. C. It is a syntax error.
  701.  
  702. D. It multiplies the value by -1 twice.
  703.  
  704. Answer: B. It converts a value to a boolean with the same truthiness.
  705.  
  706. Explanation: The !! operator converts a value to a boolean while preserving its truthiness. The first ! negates the value (converting it to a boolean), and the second ! negates it again.
  707. Question 48 What is the correct syntax for importing a module in modern JavaScript?
  708.  
  709. A. import name from “module-name”;
  710.  
  711. B. require(“module-name”);
  712.  
  713. C. module.import(“module-name”);
  714.  
  715. D. include “module-name”;
  716.  
  717. Answer: A. import name from “module-name”;
  718.  
  719. Explanation: In modern JavaScript (ES6 and later), the import statement is used to import functions, objects, or primitives from another module or file.
  720. Question 49 What will be the output of the following code snippet?
  721.  
  722. console.log(1 +2+2);
  723.  
  724. A. 5
  725.  
  726. B. 122
  727.  
  728. C. 14
  729.  
  730. D. Error
  731.  
  732. Answer: B. 122
  733.  
  734. Explanation: In JavaScript, the + operator is also used for string concatenation. When used with a string, numbers are converted to strings. Hence, 1 +2” becomes “12, and “12+2” becomes “122”.
  735. Question 50 Which statement about setTimeout() function in JavaScript is true?
  736.  
  737. A. It pauses the execution of the function for a specified time.
  738.  
  739. B. It executes a function once after a specified time.
  740.  
  741. C. It repeatedly calls a function with a fixed time delay between each call.
  742.  
  743. D. It is a synchronous function.
  744.  
  745. Answer: B. It executes a function once after a specified time.
  746.  
  747. Explanation: The setTimeout() function is used to execute a function once after a specified period of time in milliseconds. It is asynchronous, meaning the rest of the code will continue to execute while the timer counts down.
  748. Question 51 What does the following JavaScript code return?
  749.  
  750. [1, 2, 3].map(num => {
  751.  
  752.  if (typeof num === ‘number’) return;
  753.  
  754.  return num * 2;
  755.  
  756. });
  757.  
  758. A. [undefined, undefined, undefined]
  759.  
  760. B. [null, null, null]
  761.  
  762. C. [2, 4, 6]
  763.  
  764. D. []
  765.  
  766. Answer: A. [undefined, undefined, undefined]
  767.  
  768. Explanation: The map function here checks if each element is a number and if so, it returns undefined (since there’s no explicit return value). If the element is not a number, it would return num * 2, but since all elements are numbers, the array will be filled with undefined.
  769. Question 52 What does the following code output?
  770.  
  771. let a = [1, 2, 3];
  772.  
  773. let b = a;
  774.  
  775. b.push(4);
  776.  
  777. console.log(a);
  778.  
  779. A. [1, 2, 3]
  780.  
  781. B. [1, 2, 3, 4]
  782.  
  783. C. TypeError
  784.  
  785. D. undefined
  786.  
  787. Answer: B. [1, 2, 3, 4]
  788.  
  789. Explanation: Since b is a reference to the same array as a, modifying b will also modify a. Therefore, when you push 4 into b, a is also updated.
  790. Question 53 Which of the following is a way to define an object in JavaScript?
  791.  
  792. A. var person = {firstName:”John”, lastName:”Doe”};
  793.  
  794. B. var person = Object(“firstName: John, lastName: Doe”);
  795.  
  796. C. var person = new Object(firstName: “John”, lastName: “Doe”);
  797.  
  798. D. var person = {Person(“firstName: John, lastName: Doe”)};
  799.  
  800. Answer: A. var person = {firstName:”John”, lastName:”Doe”};
  801.  
  802. Explanation: Option A uses object literal syntax, which is a common and concise way to create objects in JavaScript.
  803. Question 54 How can you detect if a variable is an array in JavaScript?
  804.  
  805. A. variable.isArray()
  806.  
  807. B. Array.isArray(variable)
  808.  
  809. C. variable instanceof Array
  810.  
  811. D. Both B and C are correct
  812.  
  813. Answer: D. Both B and C are correct
  814.  
  815. Explanation: Array.isArray(variable) is a standard method for determining if a variable is an array. variable instanceof Array also works for this purpose.
  816. Question 55 What does the following JavaScript code do?
  817.  
  818. let x =5;
  819.  
  820. let y = x++;
  821.  
  822. A. Increments x and then assigns the incremented value to y.
  823.  
  824. B. Assigns the value of x to y and then increments x.
  825.  
  826. C. Results in a runtime error.
  827.  
  828. D. None of the above.
  829.  
  830. Answer: B. Assigns the value of x to y and then increments x.
  831.  
  832. Explanation: The x++ operator first returns the value of x and then increments it. So, y gets the value of x before incrementation.
  833. Question 56 In JavaScript, which method is used to remove the first element from an array and return that element?
  834.  
  835. A. shift()
  836.  
  837. B. unshift()
  838.  
  839. C. pop()
  840.  
  841. D. push()
  842.  
  843. Answer: A. shift()
  844.  
  845. Explanation: The shift() method removes the first element from an array and returns that removed element.
  846. Question 57 What is the main difference between let and const in JavaScript?
  847.  
  848. A. let declarations are block-scoped, const declarations are not.
  849.  
  850. B. let allows reassignment, const does not.
  851.  
  852. C. let is function-scoped, const is block-scoped.
  853.  
  854. D. let can store objects and arrays, const cannot.
  855.  
  856. Answer: B. let allows reassignment, const does not.
  857.  
  858. Explanation: Both let and const are block-scoped. However, variables declared with let can be reassigned, while variables declared with const cannot be reassigned.
  859. Question 58 What is the output of the following code?
  860.  
  861. console.log(typeof null);
  862.  
  863. A. “null
  864.  
  865. B. “undefined
  866.  
  867. C. “object”
  868.  
  869. D. “number”
  870.  
  871. Answer: C. “object”
  872.  
  873. Explanation: In JavaScript, typeof null returns “object”. This is actually a long-standing bug in JavaScript, as null is not really an object.
  874. Question 59 What will be logged in the console in the following code?
  875.  
  876. let num = 8;
  877.  
  878. let newNum = num++;
  879.  
  880. console.log(num, newNum);
  881.  
  882. A. 8, 8
  883.  
  884. B. 8, 9
  885.  
  886. C. 9, 8
  887.  
  888. D. 9, 9
  889.  
  890. Answer: C. 9, 8
  891.  
  892. Explanation: num++ is a post-increment operator, so it returns num (which is 8) before incrementing it. Hence, newNum is 8, and num becomes 9.
  893. Question 60 Which statement will correctly call a function named myFunction?
  894.  
  895. A. call myFunction();
  896.  
  897. B. myFunction();
  898.  
  899. C. call function myFunction();
  900.  
  901. D. execute myFunction();
  902.  
  903. Answer: B. myFunction();
  904.  
  905. Explanation: In JavaScript, you call a function by writing the function’s name followed by parentheses. So, myFunction(); is the correct syntax.
  906. Question 61 What is the output of this code snippet?
  907.  
  908. let x = “Hello”;
  909.  
  910. let y = new String(“Hello”);
  911.  
  912. console.log(x === y);
  913.  
  914. A. true
  915.  
  916. B. false
  917.  
  918. C. TypeError
  919.  
  920. D. undefined
  921.  
  922. Answer: B. false
  923.  
  924. Explanation: x is a string literal, while y is an object created by the String constructor. In JavaScript, the === operator checks for both value and type, so these two are not considered the same.
  925. Question 62 Which method can be used to combine two or more arrays in JavaScript?
  926.  
  927. A. Array.join()
  928.  
  929. B. Array.concat()
  930.  
  931. C. Array.merge()
  932.  
  933. D. Array.combine()
  934.  
  935. Answer: B. Array.concat()
  936.  
  937. Explanation: Array.concat() is used to merge two or more arrays into a new array without modifying the original arrays.
  938. Question 63 What will the following code log to the console?
  939.  
  940. console.log(typeof (() => {}));
  941.  
  942. A. “function
  943.  
  944. B. “object”
  945.  
  946. C. “undefined
  947.  
  948. D. “string”
  949.  
  950. Answer: A. “function
  951.  
  952. Explanation: An arrow function () => {} is a type of function, so typeof for an arrow function will returnfunction”.
  953. Question 64 Which of the following is the correct way to create an object in JavaScript?
  954.  
  955. A. var obj = {};
  956.  
  957. B. var obj = new Object();
  958.  
  959. C. var obj = Object.create(null);
  960.  
  961. D. All of the above
  962.  
  963. Answer: D. All of the above
  964.  
  965. Explanation: All three methods are correct for creating an object in JavaScript. The first uses object literal syntax, the second uses the Object constructor, and the third uses Object.create().
  966. Question 65 What does the following JavaScript code return?
  967.  
  968. “Cat” && “Dog”
  969.  
  970. A. “Cat”
  971.  
  972. B. “Dog”
  973.  
  974. C. true
  975.  
  976. D. false
  977.  
  978. Answer: B. “Dog”
  979.  
  980. Explanation: The logical AND (&&) operator returns the value of the second operand if the first is truthy. Since “Cat” is truthy, it returns “Dog”.
  981. Question 66 What does the delete operator in JavaScript do?
  982.  
  983. A. It deletes variables.
  984.  
  985. B. It removes properties from objects.
  986.  
  987. C. It deletes elements from an array.
  988.  
  989. D. It removes a file from the server.
  990.  
  991. Answer: B. It removes properties from objects.
  992.  
  993. Explanation: The delete operator is used to remove properties from objects. It does not delete variables or array elements (it will leave a hole in the array).
  994. Question 67 What does the following code output?
  995.  
  996. let x = 1;
  997.  
  998. let y = x !== 2;
  999.  
  1000. console.log(y);
  1001.  
  1002. A. 1
  1003.  
  1004. B. false
  1005.  
  1006. C. true
  1007.  
  1008. D. undefined
  1009.  
  1010. Answer: C. true
  1011.  
  1012. Explanation: The expression x !== 2 is true because x (which is 1) is not equal to 2.
  1013. Question 68 What is the output of this code snippet?
  1014.  
  1015. console.log(typeof “Hello” === “string”);
  1016.  
  1017. A. true
  1018.  
  1019. B. false
  1020.  
  1021. C. TypeError
  1022.  
  1023. D. undefined
  1024.  
  1025. Answer: A. true
  1026.  
  1027. Explanation: typeof “Hello” returns “string”, and so the comparison “string” === “string” is true.
  1028. Question 69 What is the purpose of template literals in JavaScript?
  1029.  
  1030. A. They allow you to perform complex calculations.
  1031.  
  1032. B. They enable secure data transmission.
  1033.  
  1034. C. They provide an easy way to interpolate variables and expressions into strings.
  1035.  
  1036. D. They improve the performance of string operations.
  1037.  
  1038. Answer: C. They provide an easy way to interpolate variables and expressions into strings.
  1039.  
  1040. Explanation: Template literals (denoted by backticks `) allow embedded expressions and variables, making it easier to create complex strings.
  1041. Question 70 What does the ?. operator signify in JavaScript?
  1042.  
  1043. A. Nullish Coalescing
  1044.  
  1045. B. Logical AND
  1046.  
  1047. C. Optional Chaining
  1048.  
  1049. D. Exclusive OR
  1050.  
  1051. Answer: C. Optional Chaining
  1052.  
  1053. Explanation: The optional chaining operator ?. allows you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid.
  1054. Question 71 What is the purpose of the Array.prototype.filter() method in JavaScript?
  1055.  
  1056. A. To update every element in an array based on a condition.
  1057.  
  1058. B. To create a new array with elements that pass a test provided by a function.
  1059.  
  1060. C. To return the first element that satisfies a provided testing function.
  1061.  
  1062. D. To execute a function once for each array element.
  1063.  
  1064. Answer: B. To create a new array with elements that pass a test provided by a function.
  1065.  
  1066. Explanation: Array.prototype.filter() creates a new array with all elements that pass the test implemented by the provided function.
  1067. Question 72 What is the output of this JavaScript code?
  1068.  
  1069. let a = 3;
  1070.  
  1071. let b = new Number(3);
  1072.  
  1073. console.log(a == b);
  1074.  
  1075. console.log(a === b);
  1076.  
  1077. A. true, true
  1078.  
  1079. B. false, false
  1080.  
  1081. C. true, false
  1082.  
  1083. D. false, true
  1084.  
  1085. Answer: C. true, false
  1086.  
  1087. Explanation: a == b is true because JavaScript performs type coercion and compares the values. However, a === b is false because they are of different types (number vs object).
  1088. Question 73 In JavaScript, which of these statements will create a copy of an object?
  1089.  
  1090. A. let objCopy = Object.assign({}, obj);
  1091.  
  1092. B. let objCopy = {…obj};
  1093.  
  1094. C. let objCopy = JSON.parse(JSON.stringify(obj));
  1095.  
  1096. D. All of the above
  1097.  
  1098. Answer: D. All of the above
  1099.  
  1100. Explanation: All three methods can be used to create a shallow copy of an object in JavaScript.
  1101. Question 74 What will the following JavaScript code log to the console?
  1102.  
  1103. function test() {
  1104.  
  1105.  return
  1106.  
  1107.  {
  1108.  
  1109.  message: “hello”
  1110.  
  1111.  };
  1112.  
  1113. }
  1114.  
  1115. console.log(test());
  1116.  
  1117. A. { message: “hello” }
  1118.  
  1119. B. undefined
  1120.  
  1121. C. SyntaxError
  1122.  
  1123. D. null
  1124.  
  1125. Answer: B. undefined
  1126.  
  1127. Explanation: Due to JavaScript’s automatic semicolon insertion, the return statement is considered to end after return. Therefore, the function returns undefined.
  1128. Question 75 Which JavaScript method is used for parsing a string to an integer?
  1129.  
  1130. A. Number.parse()
  1131.  
  1132. B. Math.parseInt()
  1133.  
  1134. C. parseInt()
  1135.  
  1136. D. String.toInt()
  1137.  
  1138. Answer: C. parseInt()
  1139.  
  1140. Explanation: parseInt() is a function used to parse a string and return an integer.
  1141. Question 76 What does the map() method do in JavaScript?
  1142.  
  1143. A. It changes the original array.
  1144.  
  1145. B. It performs a redirect to a new URL.
  1146.  
  1147. C. It calls a provided function on every element in an array and creates a new array.
  1148.  
  1149. D. It concatenates all elements of an array into a string.
  1150.  
  1151. Answer: C. It calls a provided function on every element in an array and creates a new array.
  1152.  
  1153. Explanation: map() creates a new array with the results of calling a provided function on every element in the calling array.
  1154. Question 77 How can you add a key-value pair to a JavaScript object after it has been created?
  1155.  
  1156. A. obj[key] = value;
  1157.  
  1158. B. obj.add(key, value);
  1159.  
  1160. C. obj.push({key: value});
  1161.  
  1162. D. obj.concat({key: value});
  1163.  
  1164. Answer: A. obj[key] = value;
  1165.  
  1166. Explanation: You can add a new key-value pair to an object by using the syntax obj[key] = value; where key is the name of the property and value is the value you want to assign.
  1167. Question 78 Which statement about JavaScript’s switch statement is correct?
  1168.  
  1169. A. The switch statement is used to select one of many code blocks to be executed.
  1170.  
  1171. B. The switch statement can only test for equality with string values.
  1172.  
  1173. C. The switch statement tests expressions strictly (using ===).
  1174.  
  1175. D. The switch statement can only have one case for each value.
  1176.  
  1177. Answer: A. The switch statement is used to select one of many code blocks to be executed.
  1178.  
  1179. Explanation: A switch statement evaluates an expression and executes code blocks based on the case that matches the expression’s value. It can test for equality with any data type, and multiple cases can match the same value.
  1180. Question 79 What will the following code output?
  1181.  
  1182. console.log(5+ 2);
  1183.  
  1184. console.log(5” – 2);
  1185.  
  1186. A. 52 and 3
  1187.  
  1188. B. 7 and 3
  1189.  
  1190. C. 52 and NaN
  1191.  
  1192. D. 7 and NaN
  1193.  
  1194. Answer: A. 52 and 3
  1195.  
  1196. Explanation: In JavaScript, the + operator is used for string concatenation as well as addition. So5+ 2 results in52”. The – operator, however, is only for subtraction, so “5” – 2 results in 3.
  1197. Question 80 In JavaScript, how do you check if a variable a is an instance of an object A?
  1198.  
  1199. A. a.instanceof(A)
  1200.  
  1201. B. A.instanceof(a)
  1202.  
  1203. C. a instanceof A
  1204.  
  1205. D. instanceof a(A)
  1206.  
  1207. Answer: C. a instanceof A
  1208.  
  1209. Explanation: The instanceof operator checks whether an object in its left-hand operand is an instance of an object in its right-hand operand.
  1210. Question 81 What is a typical use case for an anonymous function in JavaScript?
  1211.  
  1212. A. As a callback function
  1213.  
  1214. B. For recursive function calls
  1215.  
  1216. C. To define a class
  1217.  
  1218. D. To initialize global variables
  1219.  
  1220. Answer: A. As a callback function
  1221.  
  1222. Explanation: Anonymous functions are commonly used as callback functions in JavaScript. They are functions that don’t have a name and can be defined in the place where they are used, often in response to events or as arguments to other functions.
  1223. Question 82 What will the following code output?
  1224.  
  1225. let num = 10;
  1226.  
  1227. console.log(++num);
  1228.  
  1229. A. 10
  1230.  
  1231. B. 11
  1232.  
  1233. C. 9
  1234.  
  1235. D. TypeError
  1236.  
  1237. Answer: B. 11
  1238.  
  1239. Explanation: The ++ operator before the variable (++num) is a pre-increment operator, which increments num by 1 before returning its value. So, it outputs 11.
  1240. Question 83 Which of the following is a correct method to clone an array in JavaScript?
  1241.  
  1242. A. let newArray = […oldArray];
  1243.  
  1244. B. let newArray = Array.from(oldArray);
  1245.  
  1246. C. let newArray = oldArray.slice();
  1247.  
  1248. D. All of the above
  1249.  
  1250. Answer: D. All of the above
  1251.  
  1252. Explanation: All three methods (spread syntax, Array.from(), and slice()) are correct for cloning an array in JavaScript. They create a new array instance with the same elements.
  1253. Question 84 What does the finally block do in a try-catch statement?
  1254.  
  1255. A. It runs only if an error occurs in the try block.
  1256.  
  1257. B. It runs regardless of the result of the try-catch blocks.
  1258.  
  1259. C. It replaces the catch block if no errors occur.
  1260.  
  1261. D. It is used to finalize object cleanup.
  1262.  
  1263. Answer: B. It runs regardless of the result of the try-catch blocks.
  1264.  
  1265. Explanation: The finally block executes after the try and catch blocks but before statements following the try-catch statement. It always executes, regardless of whether an exception was thrown or caught.
  1266. Question 85 What is the output of the following JavaScript code?
  1267.  
  1268. let x =0;
  1269.  
  1270. console.log(Boolean(x));
  1271.  
  1272. A. true
  1273.  
  1274. B. false
  1275.  
  1276. C. 0
  1277.  
  1278. D. “0
  1279.  
  1280. Answer: A. true
  1281.  
  1282. Explanation: In JavaScript, the string “0” is truthy, so Boolean(0) returns true.
  1283. Question 86 How do you find the character at a specific position in a string in JavaScript?
  1284.  
  1285. A. string.charAt(index)
  1286.  
  1287. B. string.at(index)
  1288.  
  1289. C. string.charCodeAt(index)
  1290.  
  1291. D. string.characterAt(index)
  1292.  
  1293. Answer: A. string.charAt(index)
  1294.  
  1295. Explanation: charAt(index) method returns the character at the specified index in a string.
  1296. Question 87 What is the use of the new keyword in JavaScript?
  1297.  
  1298. A. To create a new object instance from a class or constructor function.
  1299.  
  1300. B. To create a new variable.
  1301.  
  1302. C. To declare a new function.
  1303.  
  1304. D. To initialize a new array.
  1305.  
  1306. Answer: A. To create a new object instance from a class or constructor function.
  1307.  
  1308. Explanation: The new keyword is used to create an instance of an object that has a constructor function.
  1309. Question 88 Which method is used to add an event listener in modern JavaScript?
  1310.  
  1311. A. object.addEventListener(event, function)
  1312.  
  1313. B. object.attachEvent(event, function)
  1314.  
  1315. C. object.onEvent = function
  1316.  
  1317. D. object.captureEvent(event, function)
  1318.  
  1319. Answer: A. object.addEventListener(event, function)
  1320.  
  1321. Explanation: addEventListener() is the modern method to attach an event listener to an element. It allows you to specify the event to listen for and the callback function to execute when the event is triggered.
  1322. Question 89 What is the result of the following expression?
  1323.  
  1324. “Hello” – “World”
  1325.  
  1326. A. NaN
  1327.  
  1328. B. 0
  1329.  
  1330. C. “HelloWorld”
  1331.  
  1332. D. TypeError
  1333.  
  1334. Answer: A. NaN
  1335.  
  1336. Explanation: Attempting arithmetic subtraction on non-numeric strings results in NaN (Not a Number).
  1337. Question 90 How can you convert a JSON object to a string in JavaScript?
  1338.  
  1339. A. JSON.stringify(jsonObject)
  1340.  
  1341. B. jsonObject.toString()
  1342.  
  1343. C. JSON.parse(jsonObject)
  1344.  
  1345. D. String(jsonObject)
  1346.  
  1347. Answer: A. JSON.stringify(jsonObject)
  1348.  
  1349. Explanation: JSON.stringify(jsonObject) is used to convert a JSON object to a string.
  1350. Question 91 What does the static keyword do in JavaScript classes?
  1351.  
  1352. A. Makes a method or property belong to the class, rather than an instance of the class.
  1353.  
  1354. B. Declares a static type for variables.
  1355.  
  1356. C. Prevents a class from being instantiated.
  1357.  
  1358. D. Indicates that a property or method can’t be changed.
  1359.  
  1360. Answer: A. Makes a method or property belong to the class, rather than an instance of the class.
  1361.  
  1362. Explanation: The static keyword in JavaScript classes is used to define methods or properties on the class itself, rather than on instances of the class.
  1363. Question 92 Which of the following is not a valid JavaScript variable name?
  1364.  
  1365. A. 2names
  1366.  
  1367. B. _name
  1368.  
  1369. C. $name
  1370.  
  1371. D. name2
  1372.  
  1373. Answer: A. 2names
  1374.  
  1375. Explanation: In JavaScript, a variable name cannot start with a number. It can start with a letter, $, or _.
  1376. Question 93 How do you stop an interval timer in JavaScript?
  1377.  
  1378. A. clearInterval(timerID)
  1379.  
  1380. B. stopInterval(timerID)
  1381.  
  1382. C. removeInterval(timerID)
  1383.  
  1384. D. endInterval(timerID)
  1385.  
  1386. Answer: A. clearInterval(timerID)
  1387.  
  1388. Explanation: clearInterval(timerID) is used to stop a timer set with setInterval().
  1389. Question 94 What is the main difference between the == and === operators in JavaScript?
  1390.  
  1391. A. == checks for equality and === checks for data type.
  1392.  
  1393. B. == performs type coercion while === does not.
  1394.  
  1395. C. == is used to compare strings and === is used to compare numbers.
  1396.  
  1397. D. There is no difference.
  1398.  
  1399. Answer: B. == performs type coercion while === does not.
  1400.  
  1401. Explanation: The == operator compares two values after converting them to a common type (type coercion), whereas === compares both value and type without coercion.
  1402. Question 95 Which of these methods can be used to send a request to a server in JavaScript?
  1403.  
  1404. A. XMLHttpRequest
  1405.  
  1406. B. fetch
  1407.  
  1408. C. axios
  1409.  
  1410. D. All of the above
  1411.  
  1412. Answer: D. All of the above
  1413.  
  1414. Explanation: All three, XMLHttpRequest, fetch, and axios (a third-party library), can be used to make HTTP requests to a server in JavaScript.
  1415. Question 96 What will the following code output?
  1416.  
  1417. console.log(!!null);
  1418.  
  1419. A. true
  1420.  
  1421. B. false
  1422.  
  1423. C. null
  1424.  
  1425. D. TypeError
  1426.  
  1427. Answer: B. false
  1428.  
  1429. Explanation: The !! operator converts a value to a boolean equivalent. Since null is falsy in JavaScript, !!null will be false.
  1430. Question 97 What is the output of the following JavaScript code?
  1431.  
  1432. console.log(1 +2+ 3);
  1433.  
  1434. A. 6
  1435.  
  1436. B. “123
  1437.  
  1438. C. “15
  1439.  
  1440. D. TypeError
  1441.  
  1442. Answer: B. “123
  1443.  
  1444. Explanation: In this expression, JavaScript performs string concatenation from left to right, resulting in12” followed by “123”.
  1445. Question 98 Which JavaScript method can be used to check if an object is an array?
  1446.  
  1447. A. Array.isArray()
  1448.  
  1449. B. isArray()
  1450.  
  1451. C. typeof
  1452.  
  1453. D. instanceof Array
  1454.  
  1455. Answer: A. Array.isArray()
  1456.  
  1457. Explanation: Array.isArray() is the preferred method to check if an object is an array. typeof will return “object” for arrays, and instanceof Array can give false negatives if arrays are from different frames.
  1458. Question 99 What does the reduce() method do in JavaScript?
  1459.  
  1460. A. It reduces the size of an array.
  1461.  
  1462. B. It applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
  1463.  
  1464. C. It filters out elements in an array that do not match a given condition.
  1465.  
  1466. D. It executes a provided function once for each array element.
  1467.  
  1468. Answer: B. It applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
  1469.  
  1470. Explanation: The reduce() method in JavaScript applies a function to an accumulator and each element in the array to reduce it to a single value.
  1471. Question 100 How can you add a comment in a JavaScript file?
  1472.  
  1473. A. <!– This is a comment –>
  1474.  
  1475. B. // This is a comment
  1476.  
  1477. C. /* This is a comment */
  1478.  
  1479. D. Both B and C
  1480.  
  1481. Answer: D. Both B and C
  1482.  
  1483. Explanation: In JavaScript, // is used for single-line comments and /* */ for multi-line comments.
  1484. Question 101 What will the following JavaScript code output?
  1485.  
  1486. console.log(typeof NaN);
  1487.  
  1488. A. “number”
  1489.  
  1490. B. “NaN
  1491.  
  1492. C. “undefined
  1493.  
  1494. D. “object”
  1495.  
  1496. Answer: A. “number”
  1497.  
  1498. Explanation: In JavaScript, the type of NaN (Not a Number) is ironically “number”.
  1499. Question 102 Which of the following is true about JavaScript’s arrow functions?
  1500.  
  1501. A. They can be used as constructors.
  1502.  
  1503. B. They have their own this context.
  1504.  
  1505. C. They are not hoisted.
  1506.  
  1507. D. They can contain a yield keyword.
  1508.  
  1509. Answer: C. They are not hoisted.
  1510.  
  1511. Explanation: Arrow functions in JavaScript are not hoisted, meaning they must be defined before they are used. Unlike regular functions, they do not have their own this context and cannot be used as constructors.
  1512. Question 103 How do you create a read-only property in an object in JavaScript?
  1513.  
  1514. A. Using the const keyword.
  1515.  
  1516. B. Using the Object.defineProperty() method.
  1517.  
  1518. C. Using the readonly attribute in the object declaration.
  1519.  
  1520. D. It is not possible to create read-only properties.
  1521.  
  1522. Answer: B. Using the Object.defineProperty() method.
  1523.  
  1524. Explanation: Object.defineProperty() allows you to define a property on an object and set its attributes, such as writable, to make it read-only.
  1525. Question 104 What will the following JavaScript code output?
  1526.  
  1527. let str = “Hello World!;
  1528.  
  1529. console.log(str.slice(0, 5));
  1530.  
  1531. A. “Hello”
  1532.  
  1533. B. “Hello World”
  1534.  
  1535. C. “World!
  1536.  
  1537. D. “H”
  1538.  
  1539. Answer: A. “Hello”
  1540.  
  1541. Explanation: The slice() method extracts a section of a string and returns it as a new string. slice(0, 5) extracts the first five characters.
  1542. Question 105 Which of these is a correct method to create a new and empty array in JavaScript?
  1543.  
  1544. A. let arr = new Array();
  1545.  
  1546. B. let arr = [];
  1547.  
  1548. C. let arr = Array();
  1549.  
  1550. D. All of the above
  1551.  
  1552. Answer: D. All of the above
  1553.  
  1554. Explanation: All three statements are valid ways to create an empty array in JavaScript.
  1555. Question 106 What is event bubbling in JavaScript?
  1556.  
  1557. A. When the browser’s default event handling is prevented.
  1558.  
  1559. B. The concept where an event propagates from the target element up through the ancestors in the DOM tree.
  1560.  
  1561. C. The process of binding two different events together.
  1562.  
  1563. D. A specific type of event that moves from the outermost element to the target element.
  1564.  
  1565. Answer: B. The concept where an event propagates from the target element up through the ancestors in the DOM tree.
  1566.  
  1567. Explanation: Event bubbling is a type of event propagation in the DOM where events start from the deepest (innermost) element and then propagate up through the parents.
  1568. Question 107 Which of the following methods can be used to send JSON data to the server?
  1569.  
  1570. A. XMLHttpRequest.send()
  1571.  
  1572. B. fetch()
  1573.  
  1574. C. axios.post()
  1575.  
  1576. D. All of the above
  1577.  
  1578. Answer: D. All of the above
  1579.  
  1580. Explanation: All these methods (XMLHttpRequest.send(), fetch(), and axios.post()) can be used to send JSON data to a server in JavaScript.
  1581. Question 108 What is the purpose of the async keyword in JavaScript?
  1582.  
  1583. A. To pause the execution of a function until a promise is resolved.
  1584.  
  1585. B. To indicate that a function can run asynchronously.
  1586.  
  1587. C. To automatically optimize code execution.
  1588.  
  1589. D. To define a new thread for running the function.
  1590.  
  1591. Answer: B. To indicate that a function can run asynchronously.
  1592.  
  1593. Explanation: The async keyword is used before a function to signify that it returns a promise and can be executed asynchronously.
  1594. Question 109 What does the spread operator do in JavaScript?
  1595.  
  1596. A. Spreads the elements of an iterable (like an array) into individual elements.
  1597.  
  1598. B. Joins multiple arrays into a single array.
  1599.  
  1600. C. Increases the value of numeric elements in an array.
  1601.  
  1602. D. Spreads the properties of an object over time.
  1603.  
  1604. Answer: A. Spreads the elements of an iterable (like an array) into individual elements.
  1605.  
  1606. Explanation: The spread operator () allows an iterable (e.g., array) to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected.
  1607. Question 110 How can you get the total number of arguments passed to a function in JavaScript?
  1608.  
  1609. A. arguments.length
  1610.  
  1611. B. arguments.count
  1612.  
  1613. C. arguments.size
  1614.  
  1615. D. this.arguments.length
  1616.  
  1617. Answer: A. arguments.length
  1618.  
  1619. Explanation: The arguments object in a function contains an array of the arguments used when the function was called and arguments.length will give you the number of arguments passed to the function.
  1620. Question 111 What is the output of this JavaScript code?
  1621.  
  1622. let x = 10;
  1623.  
  1624. let y =10;
  1625.  
  1626. console.log(x == y);
  1627.  
  1628. console.log(x === y);
  1629.  
  1630. A. true, true
  1631.  
  1632. B. true, false
  1633.  
  1634. C. false, true
  1635.  
  1636. D. false, false
  1637.  
  1638. Answer: B. true, false
  1639.  
  1640. Explanation: The == operator checks for value equality with type coercion, so 10 (number) is equal to “10(string) in terms of value. The === operator checks for both value and type equality without type coercion, so they are not strictly equal.
  1641. Question 112 Which of these is not a valid way to declare a function in JavaScript?
  1642.  
  1643. A. function myFunc() {}
  1644.  
  1645. B. var myFunc = function() {};
  1646.  
  1647. C. var myFunc = new Function();
  1648.  
  1649. D. var myFunc => {};
  1650.  
  1651. Answer: D. var myFunc => {};
  1652.  
  1653. Explanation: The correct syntax for an arrow function is var myFunc = () => {};. The other options are valid ways to declare a function.
  1654. Question 113 What will the following JavaScript code output?
  1655.  
  1656. console.log(0.1 + 0.2 === 0.3);
  1657.  
  1658. A. true
  1659.  
  1660. B. false
  1661.  
  1662. C. TypeError
  1663.  
  1664. D. undefined
  1665.  
  1666. Answer: B. false
  1667.  
  1668. Explanation: Due to floating point precision issues in JavaScript, 0.1 + 0.2 does not exactly equal 0.3.
  1669. Question 114 In JavaScript, what is a truthy value?
  1670.  
  1671. A. A value that is strictly true.
  1672.  
  1673. B. A value that translates to true when evaluated in a boolean context.
  1674.  
  1675. C. A value that is not false.
  1676.  
  1677. D. A value that is a boolean data type.
  1678.  
  1679. Answer: B. A value that translates to true when evaluated in a boolean context.
  1680.  
  1681. Explanation: In JavaScript, a truthy value is any value that is not falsy (i.e., not false, 0, “”, null, undefined, or NaN). When evaluated in a boolean context, such as an if statement, these values will be treated as true.
  1682. Question 115 Which of the following methods will correctly round the number 7.25 to the nearest integer in JavaScript?
  1683.  
  1684. A. Math.round(7.25)
  1685.  
  1686. B. Math.ceil(7.25)
  1687.  
  1688. C. Math.floor(7.25)
  1689.  
  1690. D. parseInt(7.25)
  1691.  
  1692. Answer: A. Math.round(7.25)
  1693.  
  1694. Explanation: Math.round(7.25) rounds the number to the nearest integer. Math.ceil() rounds up, Math.floor() rounds down, and parseInt() truncates the decimal part.
  1695. Question 116 How can you remove a specific element from an array in JavaScript?
  1696.  
  1697. A. array.pop(element)
  1698.  
  1699. B. delete array[index]
  1700.  
  1701. C. array.splice(index, 1)
  1702.  
  1703. D. array.remove(element)
  1704.  
  1705. Answer: C. array.splice(index, 1)
  1706.  
  1707. Explanation: array.splice(index, 1) is used to remove a specific element from an array by its index. pop() removes the last element, delete will leave an undefined hole in the array, and remove() is not a standard array method.
  1708. Question 117 What will the following JavaScript code output?
  1709.  
  1710. let a = “JavaScript”;
  1711.  
  1712. let b = a.substring(4, 7);
  1713.  
  1714. console.log(b);
  1715.  
  1716. A. “Script”
  1717.  
  1718. B. “ava”
  1719.  
  1720. C. “Java”
  1721.  
  1722. D. “aSc”
  1723.  
  1724. Answer: D. “aSc”
  1725.  
  1726. Explanation: substring(4, 7) extracts characters from index 4 to 7, not including 7, from the string a. In “JavaScript”, these characters are aSc.
  1727. Question 118 Which of the following is a way to define an arrow function that returns the square of its input in JavaScript?
  1728.  
  1729. A. const square = (x) => { x * x; };
  1730.  
  1731. B. const square = x => x * x;
  1732.  
  1733. C. const square = x => { return x * x; };
  1734.  
  1735. D. Both B and C are correct
  1736.  
  1737. Answer: D. Both B and C are correct
  1738.  
  1739. Explanation: Both options B and C correctly define an arrow function that returns the square of its input. Option B uses a concise body syntax that implicitly returns the expression, while option C uses a block body with an explicit return statement.
  1740. Question 119 In JavaScript, what is a Callback Function?
  1741.  
  1742. A. A function that is executed before another function.
  1743.  
  1744. B. A function passed into another function as an argument, which is then invoked inside the outer function.
  1745.  
  1746. C. A function that calls back to the server for data.
  1747.  
  1748. D. A method of exiting a function early.
  1749.  
  1750. Answer: B. A function passed into another function as an argument, which is then invoked inside the outer function.
  1751.  
  1752. Explanation: A callback function is a function passed into another function as an argument, which is then executed inside the outer function to complete some kind of action or routine.
  1753. Question 120 What is the output of the following JavaScript code snippet?
  1754.  
  1755. let obj = { a: 1, b: 2 };
  1756.  
  1757. let objCopy = Object.assign({}, obj);
  1758.  
  1759. objCopy.a = 3;
  1760.  
  1761. console.log(obj.a);
  1762.  
  1763. A. 1
  1764.  
  1765. B. 2
  1766.  
  1767. C. 3
  1768.  
  1769. D. undefined
  1770.  
  1771. Answer: A. 1
  1772.  
  1773. Explanation: Object.assign({}, obj) creates a shallow copy of obj. Changing objCopy.a to 3 does not affect the original obj, so obj.a remains 1.
  1774. Question 121 Which of the following is a correct way to declare a class in JavaScript?
  1775.  
  1776. A. class MyClass { constructor() {} }
  1777.  
  1778. B. function MyClass() {}
  1779.  
  1780. C. var MyClass = class { constructor() {} }
  1781.  
  1782. D. Both A and C are correct
  1783.  
  1784. Answer: D. Both A and C are correct
  1785.  
  1786. Explanation: Both class MyClass {} and var MyClass = class {} are correct ways to declare a class in JavaScript. The first is a class declaration and the second is a class expression.
  1787. Question 122 What will this JavaScript code output?
  1788.  
  1789. console.log(4 + 5 + “px”);
  1790.  
  1791. console.log(“px” + 5 + 4);
  1792.  
  1793. A. “9px” and “px54”
  1794.  
  1795. B. “9px” and “px9”
  1796.  
  1797. C. “45px” and “px45”
  1798.  
  1799. D. “45px” and “px54”
  1800.  
  1801. Answer: A. “9px” and “px54”
  1802.  
  1803. Explanation: In the first expression, numbers are added before concatenating with a string, resulting in “9px”. In the second expression, string concatenation occurs from left to right, resulting in “px54”.
  1804. Question 123 How do you create a new Date object in JavaScript?
  1805.  
  1806. A. let now = new Date();
  1807.  
  1808. B. let now = Date.now();
  1809.  
  1810. C. let now = Date.create();
  1811.  
  1812. D. let now = new Date.now();
  1813.  
  1814. Answer: A. let now = new Date();
  1815.  
  1816. Explanation: new Date() creates a new Date object representing the current date and time. Date.now() returns the number of milliseconds since the Unix Epoch and does not create a Date object.
  1817. Question 124 Which method is used to encode a URI component in JavaScript?
  1818.  
  1819. A. encodeURI()
  1820.  
  1821. B. encodeURIComponent()
  1822.  
  1823. C. escape()
  1824.  
  1825. D. stringifyURI()
  1826.  
  1827. Answer: B. encodeURIComponent()
  1828.  
  1829. Explanation: encodeURIComponent() is used to encode a URI component by escaping all characters except alphabetic, decimal digits, and a few special characters.
  1830. Question 125 What will this code output?
  1831.  
  1832. let a = 10;
  1833.  
  1834. function myFunction() {
  1835.  
  1836.  let b = a + 10;
  1837.  
  1838.  return b;
  1839.  
  1840. }
  1841.  
  1842. console.log(myFunction());
  1843.  
  1844. A. 10
  1845.  
  1846. B. 20
  1847.  
  1848. C. undefined
  1849.  
  1850. D. ReferenceError
  1851.  
  1852. Answer: B. 20
  1853.  
  1854. Explanation: The function myFunction() adds 10 to the value of a (which is 10) and returns the result. Therefore, it will output 20.
  1855. Question 126 What is the correct way to write a JavaScript array?
  1856.  
  1857. A. var colors = 1 : (“red”), 2 : (“green”), 3 : (“blue”);
  1858.  
  1859. B. var colors = (1:”red”, 2:”green”, 3:”blue”);
  1860.  
  1861. C. var colors = [“red”, “green”, “blue”];
  1862.  
  1863. D. var colors = “red”, “green”, “blue”;
  1864.  
  1865. Answer: C. var colors = [“red”, “green”, “blue”];
  1866.  
  1867. Explanation: In JavaScript, an array is defined as a list of elements, separated by commas, and enclosed in square brackets.
  1868. Question 127 What will the following code output to the console?
  1869.  
  1870. let num = 5;
  1871.  
  1872. console.log(num++);
  1873.  
  1874. A. 5
  1875.  
  1876. B. 6
  1877.  
  1878. C. undefined
  1879.  
  1880. D. TypeError
  1881.  
  1882. Answer: A. 5
  1883.  
  1884. Explanation: num++ is the post-increment operator, so it returns the value of num before incrementing. The value of num is 5, so it logs 5 and then num becomes 6.
  1885. Question 128 Which statement about setTimeout in JavaScript is true?
  1886.  
  1887. A. It pauses the execution of the entire script for a specified duration.
  1888.  
  1889. B. It calls a function or executes a code snippet after a specified delay.
  1890.  
  1891. C. It is a blocking operation and prevents other operations from executing until it’s finished.
  1892.  
  1893. D. It can only execute a function once.
  1894.  
  1895. Answer: B. It calls a function or executes a code snippet after a specified delay.
  1896.  
  1897. Explanation: setTimeout is used to execute a function or a code snippet after a delay, specified in milliseconds. It is non-blocking and allows other code to run in the meantime.
  1898. Question 129 What does the following JavaScript code return?
  1899.  
  1900. typeof (5+ 3)
  1901.  
  1902. A. “number”
  1903.  
  1904. B. “string”
  1905.  
  1906. C. “undefined
  1907.  
  1908. D. “object”
  1909.  
  1910. Answer: B. “string”
  1911.  
  1912. Explanation: In JavaScript, the + operator with a string will result in string concatenation, so “5+ 3 becomes “53, which is a string.
  1913. Question 130 What is the primary use of the bind method in JavaScript?
  1914.  
  1915. A. To join two strings together.
  1916.  
  1917. B. To delay the execution of a function.
  1918.  
  1919. C. To create a new function that, when called, has its this keyword set to a provided value.
  1920.  
  1921. D. To bind an HTML element to a JavaScript function.
  1922.  
  1923. Answer: C. To create a new function that, when called, has its this keyword set to a provided value.
  1924.  
  1925. Explanation: The bind method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
  1926. Question 131 Which of the following is not a primitive data type in JavaScript?
  1927.  
  1928. A. string
  1929.  
  1930. B. number
  1931.  
  1932. C. boolean
  1933.  
  1934. D. object
  1935.  
  1936. Answer: D. object
  1937.  
  1938. Explanation: In JavaScript, primitive data types include string, number, boolean, undefined, null, and symbol. object is not a primitive data type; it’s a complex data type.
  1939. Question 132 What will the following JavaScript code output?
  1940.  
  1941. console.log(10’ – 5);
  1942.  
  1943. A. 5
  1944.  
  1945. B. “5
  1946.  
  1947. C. “105
  1948.  
  1949. D. NaN
  1950.  
  1951. Answer: A. 5
  1952.  
  1953. Explanation: In JavaScript, the – operator is used for subtraction and it converts strings to numbers if possible. Thus,10’ – 5 becomes 105, which equals 5.
  1954. Question 133 Which method converts a JavaScript object to a JSON string?
  1955.  
  1956. A. JSON.stringify()
  1957.  
  1958. B. JSON.parse()
  1959.  
  1960. C. Object.toString()
  1961.  
  1962. D. Object.toJSON()
  1963.  
  1964. Answer: A. JSON.stringify()
  1965.  
  1966. Explanation: JSON.stringify() method is used to convert a JavaScript object into a JSON string.
  1967. Question 134 How do you define a constant in JavaScript?
  1968.  
  1969. A. var CONSTANT_NAME = value;
  1970.  
  1971. B. constant CONSTANT_NAME = value;
  1972.  
  1973. C. let CONSTANT_NAME = value;
  1974.  
  1975. D. const CONSTANT_NAME = value;
  1976.  
  1977. Answer: D. const CONSTANT_NAME = value;
  1978.  
  1979. Explanation: The const keyword is used to define a constant in JavaScript. A constant is a value that cannot be altered once defined.
  1980. Question 135 What does the following code return?
  1981.  
  1982. isNaN(‘Hello’);
  1983.  
  1984. A. true
  1985.  
  1986. B. false
  1987.  
  1988. C. null
  1989.  
  1990. D. undefined
  1991.  
  1992. Answer: A. true
  1993.  
  1994. Explanation: isNaN(‘Hello’) returns true because ‘Hello’ is not a number.
  1995. Question 136 Which of these statements about JavaScript closures is correct?
  1996.  
  1997. A. Closures are functions with preserved data.
  1998.  
  1999. B. Closures are the same as global variables.
  2000.  
  2001. C. Closures are only created within loops.
  2002.  
  2003. D. Closures cannot access variables outside their scope.
  2004.  
  2005. Answer: A. Closures are functions with preserved data.
  2006.  
  2007. Explanation: A closure in JavaScript is a function that remembers its outer variables and can access them.
  2008. Question 137 What will the following JavaScript code output?
  2009.  
  2010. let x =5;
  2011.  
  2012. x = x + 1;
  2013.  
  2014. console.log(x);
  2015.  
  2016. A. 6
  2017.  
  2018. B. “6
  2019.  
  2020. C. “51
  2021.  
  2022. D. NaN
  2023.  
  2024. Answer: C. “51
  2025.  
  2026. Explanation: In JavaScript, when you use the + operator with a string and a number, the number is converted to a string and the two strings are concatenated. Thus,5+ 1 results in51”.
  2027. Question 138 What is the correct syntax to create an array in JavaScript?
  2028.  
  2029. A. let arr = new Array(1, 2, 3);
  2030.  
  2031. B. let arr = array(1, 2, 3);
  2032.  
  2033. C. let arr = {1, 2, 3};
  2034.  
  2035. D. let arr = [1, 2, 3];
  2036.  
  2037. Answer: D. let arr = [1, 2, 3];
  2038.  
  2039. Explanation: In JavaScript, an array is defined using square brackets [] with elements separated by commas.
  2040. Question 139 What does the following JavaScript code output?
  2041.  
  2042. let a = true;
  2043.  
  2044. let b = false;
  2045.  
  2046. console.log(a && b);
  2047.  
  2048. A. true
  2049.  
  2050. B. false
  2051.  
  2052. C. null
  2053.  
  2054. D. undefined
  2055.  
  2056. Answer: B. false
  2057.  
  2058. Explanation: The logical AND (&&) operator returns true if both operands are true. Since b is false, a && b evaluates to false.
  2059. Question 140 How do you write a conditional statement in JavaScript to check if a variable a is equal to 10?
  2060.  
  2061. A. if a = 10 {}
  2062.  
  2063. B. if (a == 10) {}
  2064.  
  2065. C. if a == 10 {}
  2066.  
  2067. D. if (a = 10) {}
  2068.  
  2069. Answer: B. if (a == 10) {}
  2070.  
  2071. Explanation: The correct syntax for an if statement in JavaScript includes parentheses around the condition and uses == or === to check for equality.
  2072. Question 141 What is the purpose of the Array.prototype.every() method in JavaScript?
  2073.  
  2074. A. To check if every element in an array passes a test implemented by the provided function.
  2075.  
  2076. B. To execute a provided function once for each array element.
  2077.  
  2078. C. To create a new array with the results of calling a provided function on every element in the calling array.
  2079.  
  2080. D. To return the first element in the array that satisfies the provided testing function.
  2081.  
  2082. Answer: A. To check if every element in an array passes a test implemented by the provided function.
  2083.  
  2084. Explanation: Array.prototype.every() tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
  2085. Question 142 What will the following JavaScript code output?
  2086.  
  2087. console.log(typeof []);
  2088.  
  2089. A. “array”
  2090.  
  2091. B. “object”
  2092.  
  2093. C. “undefined
  2094.  
  2095. D. “null
  2096.  
  2097. Answer: B. “object”
  2098.  
  2099. Explanation: In JavaScript, arrays are technically a type of object. Therefore, typeof [] returns “object”.
  2100. Question 143 Which statement is used to handle exceptions in JavaScript?
  2101.  
  2102. A. trycatch
  2103.  
  2104. B. try…except
  2105.  
  2106. C. tryfinally
  2107.  
  2108. D. try…error
  2109.  
  2110. Answer: A. trycatch
  2111.  
  2112. Explanation: The trycatch statement is used to catch exceptions in JavaScript. Optionally, a finally block can be used after the catch block.
  2113. Question 144 What is the correct way to define an async function in JavaScript?
  2114.  
  2115. A. async function myFunc() {}
  2116.  
  2117. B. function async myFunc() {}
  2118.  
  2119. C. function myFunc() async {}
  2120.  
  2121. D. async: function myFunc() {}
  2122.  
  2123. Answer: A. async function myFunc() {}
  2124.  
  2125. Explanation: An asynchronous function in JavaScript is defined using the async keyword before the function keyword, like so: async function myFunc() {}.
  2126. Question 145 What does the following JavaScript code output?
  2127.  
  2128. let x =100;
  2129.  
  2130. let y =10;
  2131.  
  2132. console.log(x / y);
  2133.  
  2134. A. “10
  2135.  
  2136. B. 10
  2137.  
  2138. C. NaN
  2139.  
  2140. D. TypeError
  2141.  
  2142. Answer: B. 10
  2143.  
  2144. Explanation: JavaScript converts string operands to numbers in all numeric operations. Therefore,100/10” results in 10.
  2145. Question 146 What is the default behavior of the this keyword in JavaScript functions?
  2146.  
  2147. A. It refers to the window/global object.
  2148.  
  2149. B. It refers to the document object.
  2150.  
  2151. C. It refers to the function itself.
  2152.  
  2153. D. It is undefined.
  2154.  
  2155. Answer: A. It refers to the window/global object.
  2156.  
  2157. Explanation: In the global execution context (outside of any function), this refers to the global object whether in strict mode or not. Inside a function, the value of this depends on how the function is called.
  2158. Question 147 How can you stop the propagation of an event in JavaScript?
  2159.  
  2160. A. event.stop()
  2161.  
  2162. B. event.preventDefault()
  2163.  
  2164. C. event.stopPropagation()
  2165.  
  2166. D. event.cancel()
  2167.  
  2168. Answer: C. event.stopPropagation()
  2169.  
  2170. Explanation: event.stopPropagation() is used to stop the propagation of an event, preventing it from being dispatched to any EventListeners after the current one.
  2171. Question 148 Which of the following is true about template literals in JavaScript?
  2172.  
  2173. A. They use single quotes.
  2174.  
  2175. B. They can contain placeholders.
  2176.  
  2177. C. They cannot span multiple lines.
  2178.  
  2179. D. They are used for writing regular expressions.
  2180.  
  2181. Answer: B. They can contain placeholders.
  2182.  
  2183. Explanation: Template literals are enclosed by backticks (`) and can contain placeholders indicated by the dollar sign and curly braces (${expression}).
  2184. Question 149 What will the following JavaScript code output?
  2185.  
  2186. let str = “JavaScript”;
  2187.  
  2188. console.log(str.substring(4));
  2189.  
  2190. A. “Script”
  2191.  
  2192. B. “Java”
  2193.  
  2194. C. “JavaScript”
  2195.  
  2196. D. “Scrip”
  2197.  
  2198. Answer: A. “Script”
  2199.  
  2200. Explanation: str.substring(4) extracts characters from the 4th index (inclusive) to the end of the string, resulting in “Script”.
  2201. Question 150 What is the result of the following expression in JavaScript?
  2202.  
  2203. 2+ 2 *2
  2204.  
  2205. A. “24
  2206.  
  2207. B. 6
  2208.  
  2209. C. “222
  2210.  
  2211. D. NaN
  2212.  
  2213. Answer: A. “24
  2214.  
  2215. Explanation: In this expression, JavaScript first evaluates the multiplication (2 *2= 4) and then performs string concatenation (2+ 4), resulting in24”.
  2216. Question 151 What will the following JavaScript code output?
  2217.  
  2218. console.log(typeof (() => {}));
  2219.  
  2220. A. “function
  2221.  
  2222. B. “object”
  2223.  
  2224. C. “undefined
  2225.  
  2226. D. “string”
  2227.  
  2228. Answer: A. “function
  2229.  
  2230. Explanation: The output will be “function, as an arrow function is still a function, and thus typeof returns “function”.
  2231. Question 152 Which method is used to serialize an object into a JSON string in JavaScript?
  2232.  
  2233. A. JSON.stringify()
  2234.  
  2235. B. JSON.parse()
  2236.  
  2237. C. Object.serialize()
  2238.  
  2239. D. Object.toString()
  2240.  
  2241. Answer: A. JSON.stringify()
  2242.  
  2243. Explanation: JSON.stringify() method is used to convert a JavaScript object into a JSON string.
  2244. Question 153 What will the following code output?
  2245.  
  2246. let a = 3;
  2247.  
  2248. let b = new Number(3);
  2249.  
  2250. console.log(a == b);
  2251.  
  2252. console.log(a === b);
  2253.  
  2254. A. true, true
  2255.  
  2256. B. false, false
  2257.  
  2258. C. true, false
  2259.  
  2260. D. false, true
  2261.  
  2262. Answer: C. true, false
  2263.  
  2264. Explanation: a == b is true because == does type coercion and both a and b represent the same value. a === b is false because === also checks the type, and a is a number while b is an object.
  2265. Question 154 Which one of these is a way to define a variable in JavaScript that restricts its scope to the block in which it is defined?
  2266.  
  2267. A. var
  2268.  
  2269. B. let
  2270.  
  2271. C. const
  2272.  
  2273. D. Both B and C
  2274.  
  2275. Answer: D. Both B and C
  2276.  
  2277. Explanation: Both let and const are used to declare variables in JavaScript with block scope. The var keyword defines a variable globally or locally to an entire function regardless of block scope.
  2278. Question 155 What is the purpose of the map() method in JavaScript?
  2279.  
  2280. A. It calls a function once for each element in an array, in order.
  2281.  
  2282. B. It transforms the elements of an array using a callback function and returns a new array.
  2283.  
  2284. C. It checks if any elements in an array pass a test provided by a function.
  2285.  
  2286. D. It combines all elements of an array into a single string.
  2287.  
  2288. Answer: B. It transforms the elements of an array using a callback function and returns a new array.
  2289.  
  2290. Explanation: map() creates a new array with the results of calling a provided function on every element in the calling array.
  2291. Question 156 What will be logged to the console in the following code?
  2292.  
  2293. let x = “Hello”;
  2294.  
  2295. let y = x;
  2296.  
  2297. x = “World”;
  2298.  
  2299. console.log(y);
  2300.  
  2301. A. Hello
  2302.  
  2303. B. World
  2304.  
  2305. C. undefined
  2306.  
  2307. D. TypeError
  2308.  
  2309. Answer: A. Hello
  2310.  
  2311. Explanation: Strings in JavaScript are immutable and passed by value. Changing x to “World” doesn’t affect the value of y, which remains “Hello”.
  2312. Question 157 Which method is used to combine two or more arrays in JavaScript?
  2313.  
  2314. A. Array.join()
  2315.  
  2316. B. Array.concat()
  2317.  
  2318. C. Array.push()
  2319.  
  2320. D. Array.append()
  2321.  
  2322. Answer: B. Array.concat()
  2323.  
  2324. Explanation: Array.concat() is used to merge two or more arrays. This method does not change the existing arrays but instead returns a new array.
  2325. Question 158 How can you add a comment in a JavaScript file?
  2326.  
  2327. A. <!– This is a comment –>
  2328.  
  2329. B. // This is a comment
  2330.  
  2331. C. /* This is a comment */
  2332.  
  2333. D. Both B and C
  2334.  
  2335. Answer: D. Both B and C
  2336.  
  2337. Explanation: In JavaScript, // is used for single-line comments and /* */ for multi-line comments.
  2338. Question 159 What is the output of the following JavaScript code?
  2339.  
  2340. console.log(10’ – 5);
  2341.  
  2342. A. 5
  2343.  
  2344. B. “5
  2345.  
  2346. C. “105
  2347.  
  2348. D. NaN
  2349.  
  2350. Answer: A. 5
  2351.  
  2352. Explanation: In JavaScript, the – operator converts the operands to numbers (if they are not already), so ’10’ – 5 is treated as 105, which equals 5.
  2353. Question 160 Which of these is a JavaScript package manager?
  2354.  
  2355. A. npm
  2356.  
  2357. B. CSS
  2358.  
  2359. C. HTML
  2360.  
  2361. D. FTP
  2362.  
  2363. Answer: A. npm
  2364.  
  2365. Explanation: npm stands for Node Package Manager. It is the default package manager for the JavaScript runtime environment Node.js.
  2366. Question 161 What is the output of the following code snippet?
  2367.  
  2368. let a = “Hello”;
  2369.  
  2370. let b = a.substring(1, 4);
  2371.  
  2372. console.log(b);
  2373.  
  2374. A. “Hell”
  2375.  
  2376. B. “ell”
  2377.  
  2378. C. “ello”
  2379.  
  2380. D. “Hel”
  2381.  
  2382. Answer: B. “ell”
  2383.  
  2384. Explanation: substring(1, 4) extracts characters from index 1 to index 4 (excluding index 4) of the string a. So, it outputs “ell”.
  2385. Question 162 Which of these is a correct method to create a deep copy of an object in JavaScript?
  2386.  
  2387. A. let newObj = Object.assign({}, obj);
  2388.  
  2389. B. let newObj = {…obj};
  2390.  
  2391. C. let newObj = JSON.parse(JSON.stringify(obj));
  2392.  
  2393. D. let newObj = obj.slice();
  2394.  
  2395. Answer: C. let newObj = JSON.parse(JSON.stringify(obj));
  2396.  
  2397. Explanation: JSON.parse(JSON.stringify(obj)) creates a deep copy of the object obj. Object.assign() and spread syntax {…obj} only create shallow copies.
  2398. Question 163 What will the following JavaScript code output?
  2399.  
  2400. console.log(!!false);
  2401.  
  2402. A. true
  2403.  
  2404. B. false
  2405.  
  2406. C. null
  2407.  
  2408. D. undefined
  2409.  
  2410. Answer: A. true
  2411.  
  2412. Explanation: The double negation !! will convert a value to its boolean equivalent. Sincefalse” is a non-empty string, it’s truthy, and thus !!false” returns true.
  2413. Question 164 Which method can be used to round a number to the nearest integer in JavaScript?
  2414.  
  2415. A. Math.round()
  2416.  
  2417. B. Math.floor()
  2418.  
  2419. C. Math.ceil()
  2420.  
  2421. D. Math.absolute()
  2422.  
  2423. Answer: A. Math.round()
  2424.  
  2425. Explanation: Math.round() rounds a number to the nearest integer.
  2426. Question 165 What does the following JavaScript code return?
  2427.  
  2428. typeof new Boolean(false)
  2429.  
  2430. A. “boolean
  2431.  
  2432. B. “object”
  2433.  
  2434. C. “false
  2435.  
  2436. D. “undefined
  2437.  
  2438. Answer: B. “object”
  2439.  
  2440. Explanation: new Boolean(false) creates a Boolean object wrapper for the value false, so typeof returns “object”.
  2441. Question 166 What is the default value of this in a JavaScript function?
  2442.  
  2443. A. The global object
  2444.  
  2445. B. null
  2446.  
  2447. C. The function itself
  2448.  
  2449. D. undefined
  2450.  
  2451. Answer: A. The global object
  2452.  
  2453. Explanation: In JavaScript, the default value of this in a function is the global object (e.g., window in a web browser). In strict mode, it’s undefined.
  2454. Question 167 How can you convert a string to an integer in JavaScript?
  2455.  
  2456. A. int.parse(string)
  2457.  
  2458. B. Number(string)
  2459.  
  2460. C. parseInt(string)
  2461.  
  2462. D. Both B and C
  2463.  
  2464. Answer: D. Both B and C
  2465.  
  2466. Explanation: Both Number(string) and parseInt(string) can be used to convert a string to an integer in JavaScript.
  2467. Question 168 What is the output of this JavaScript code?
  2468.  
  2469. let num = 5;
  2470.  
  2471. console.log(num++);
  2472.  
  2473. A. 5
  2474.  
  2475. B. 6
  2476.  
  2477. C. TypeError
  2478.  
  2479. D. undefined
  2480.  
  2481. Answer: A. 5
  2482.  
  2483. Explanation: The num++ is a post-increment operator, which returns the current value of num (5) before incrementing it.
  2484. Question 169 Which of the following is not a valid way to declare a function in JavaScript?
  2485.  
  2486. A. function myFunc() {}
  2487.  
  2488. B. const myFunc = function() {};
  2489.  
  2490. C. const myFunc = () => {};
  2491.  
  2492. D. function = myFunc() {};
  2493.  
  2494. Answer: D. function = myFunc() {};
  2495.  
  2496. Explanation: The syntax function = myFunc() {}; is not a valid way to declare a function. The other options are valid function declarations.
  2497. Question 170 What is the correct syntax for adding comments in JavaScript?
  2498.  
  2499. A. <!– This is a comment –>
  2500.  
  2501. B. // This is a comment
  2502.  
  2503. C. /* This is a comment */
  2504.  
  2505. D. Both B and C
  2506.  
  2507. Answer: D. Both B and C
  2508.  
  2509. Explanation: In JavaScript, // is used for single-line comments and /* */ for multi-line comments.
  2510. Question 171 What is the result of “1+ 2 + 3 in JavaScript?
  2511.  
  2512. A. 6
  2513.  
  2514. B. “123
  2515.  
  2516. C. “6
  2517.  
  2518. D. undefined
  2519.  
  2520. Answer: B. “123
  2521.  
  2522. Explanation: In this expression, JavaScript performs string concatenation. Starting from the left,1(a string) concatenated with 2 results in12, which is then concatenated with 3, resulting in123”.
  2523. Question 172 Which statement about null in JavaScript is true?
  2524.  
  2525. A. null is the same as undefined.
  2526.  
  2527. B. null is a type of object.
  2528.  
  2529. C. null is a type of boolean.
  2530.  
  2531. D. null indicates the absence of a value.
  2532.  
  2533. Answer: D. null indicates the absence of a value.
  2534.  
  2535. Explanation: null in JavaScript represents the intentional absence of any object value. It is not the same as undefined, which represents a value not yet assigned.
  2536. Question 173 How do you find the length of a string str in JavaScript?
  2537.  
  2538. A. str.length()
  2539.  
  2540. B. length(str)
  2541.  
  2542. C. str.length
  2543.  
  2544. D. str.getSize()
  2545.  
  2546. Answer: C. str.length
  2547.  
  2548. Explanation: In JavaScript, the length of a string can be found using the .length property. str.length returns the length of the string str.
  2549. Question 174 What does the following JavaScript code output?
  2550.  
  2551. let x = 10;
  2552.  
  2553. console.log(++x);
  2554.  
  2555. A. 10
  2556.  
  2557. B. 11
  2558.  
  2559. C. NaN
  2560.  
  2561. D. undefined
  2562.  
  2563. Answer: B. 11
  2564.  
  2565. Explanation: The ++x is a pre-increment operator, which increments the value of x before returning it. Hence, it outputs 11.
  2566. Question 175 In JavaScript, which of these methods is used to remove the last element from an array?
  2567.  
  2568. A. pop()
  2569.  
  2570. B. push()
  2571.  
  2572. C. shift()
  2573.  
  2574. D. unshift()
  2575.  
  2576. Answer: A. pop()
  2577.  
  2578. Explanation: The pop() method removes the last element from an array and returns that element.
  2579. Question 176 What does the || operator represent in JavaScript?
  2580.  
  2581. A. AND
  2582.  
  2583. B. OR
  2584.  
  2585. C. NOT
  2586.  
  2587. D. XOR
  2588.  
  2589. Answer: B. OR
  2590.  
  2591. Explanation: The || operator represents the logical OR in JavaScript. It returns true if either of its operands is true.
  2592. Question 177 Which of the following is not a reserved word in JavaScript?
  2593.  
  2594. A. interface
  2595.  
  2596. B. private
  2597.  
  2598. C. throws
  2599.  
  2600. D. short
  2601.  
  2602. Answer: B. private
  2603.  
  2604. Explanation: private is not a reserved word in JavaScript, though it is reserved in some other languages.
  2605. Question 178 How can you check if a variable a is less than 10 in JavaScript?
  2606.  
  2607. A. if a < 10 {}
  2608.  
  2609. B. if (a < 10) {}
  2610.  
  2611. C. if a lt 10 {}
  2612.  
  2613. D. if (a < 10); {}
  2614.  
  2615. Answer: B. if (a < 10) {}
  2616.  
  2617. Explanation: The correct syntax to check if a variable is less than a certain number in JavaScript is if (condition) {}.
  2618. Question 179 What is console.log(typeof null); going to output in JavaScript?
  2619.  
  2620. A. “null
  2621.  
  2622. B. “undefined
  2623.  
  2624. C. “object”
  2625.  
  2626. D. “number”
  2627.  
  2628. Answer: C. “object”
  2629.  
  2630. Explanation: In JavaScript, typeof null is “object”, which is a known quirk of the language. null is not actually an object, but this behavior is a holdover from the early days of JavaScript.
  2631. Question 180 Which method is used to join elements of an array into a string in JavaScript?
  2632.  
  2633. A. concat()
  2634.  
  2635. B. join()
  2636.  
  2637. C. merge()
  2638.  
  2639. D. collect()
  2640.  
  2641. Answer: B. join()
  2642.  
  2643. Explanation: The join() method joins all elements of an array into a string. You can optionally specify a separator; if no separator is specified, a comma is used by default.
  2644. Question 181 What will this JavaScript code output?
  2645.  
  2646. console.log(1== 1);
  2647.  
  2648. A. true
  2649.  
  2650. B. false
  2651.  
  2652. C. TypeError
  2653.  
  2654. D. undefined
  2655.  
  2656. Answer: A. true
  2657.  
  2658. Explanation: In JavaScript, the == operator performs type coercion and checks for value equality. Thus, the string “1” is coerced into the number 1, resulting in true.
  2659. Question 182 What is the purpose of the bind method in JavaScript?
  2660.  
  2661. A. It is used to bind an existing function to a new object.
  2662.  
  2663. B. It is used to permanently link a function to a particular value of this.
  2664.  
  2665. C. It is used to combine two functions into one.
  2666.  
  2667. D. It is used to delay the execution of a function.
  2668.  
  2669. Answer: B. It is used to permanently link a function to a particular value of this.
  2670.  
  2671. Explanation: The bind method creates a new function that, when called, has its this keyword set to the provided value. It is used to set the this context of a function regardless of how it is called.
  2672. Question 183 What is the primary use of the async keyword before a function in JavaScript?
  2673.  
  2674. A. It indicates that the function returns a promise.
  2675.  
  2676. B. It automatically splits the function into multiple threads.
  2677.  
  2678. C. It guarantees that the function will execute asynchronously.
  2679.  
  2680. D. It optimizes the function for performance.
  2681.  
  2682. Answer: A. It indicates that the function returns a promise.
  2683.  
  2684. Explanation: The async keyword is used to declare an asynchronous function, which returns a promise. It allows the use of await within the function.
  2685. Question 184 In JavaScript, which method is used to sort the elements of an array in place?
  2686.  
  2687. A. Array.sort()
  2688.  
  2689. B. Array.order()
  2690.  
  2691. C. Array.arrange()
  2692.  
  2693. D. Array.sequence()
  2694.  
  2695. Answer: A. Array.sort()
  2696.  
  2697. Explanation: Array.sort() is a method that sorts the elements of an array in place and returns the sorted array.
  2698. Question 185 What is the output of the following JavaScript code?
  2699.  
  2700. let arr = [10, 12, 15, 21];
  2701.  
  2702. for (let i = 0; i < arr.length; i++) {
  2703.  
  2704.  setTimeout(function() {
  2705.  
  2706.  console.log(‘Index:+ i +, element:+ arr[i]);
  2707.  
  2708.  }, 3000);
  2709.  
  2710. }
  2711.  
  2712. A. It logs the index and element of each array element after a delay.
  2713.  
  2714. B. It throws a syntax error.
  2715.  
  2716. C. It logs undefined for each element.
  2717.  
  2718. D. It logs the same index and element multiple times.
  2719.  
  2720. Answer: A. It logs the index and element of each array element after a delay.
  2721.  
  2722. Explanation: The setTimeout function creates a closure for each loop iteration, capturing the current value of i and the corresponding array element. After 3 seconds, it logs the index and element of each item in the array.
  2723. Question 186 How can you add a key-value pair to a JavaScript object after it has been created?
  2724.  
  2725. A. obj[key] = value;
  2726.  
  2727. B. obj.add(key, value);
  2728.  
  2729. C. obj.push({key: value});
  2730.  
  2731. D. obj.concat({key: value});
  2732.  
  2733. Answer: A. obj[key] = value;
  2734.  
  2735. Explanation: You can add a new key-value pair to an object by using the syntax obj[key] = value; where key is the name of the property and value is the value you want to assign.
  2736. Question 187 What is event delegation in JavaScript?
  2737.  
  2738. A. A way to handle events on parent elements rather than individual child elements.
  2739.  
  2740. B. A method to delegate event handling to a different element than the one that received the event.
  2741.  
  2742. C. A technique to speed up event handling.
  2743.  
  2744. D. A process to bind multiple events to a single event listener.
  2745.  
  2746. Answer: A. A way to handle events on parent elements rather than individual child elements.
  2747.  
  2748. Explanation: Event delegation is a technique where you use a single event listener on a parent element to manage all of its child events, taking advantage of event bubbling.
  2749. Question 188 Which of the following is a way to define an arrow function in JavaScript?
  2750.  
  2751. A. function myFunc() {}
  2752.  
  2753. B. var myFunc = () => {};
  2754.  
  2755. C. var myFunc = function() {};
  2756.  
  2757. D. var myFunc => {};
  2758.  
  2759. Answer: B. var myFunc = () => {};
  2760.  
  2761. Explanation: Arrow functions in JavaScript are defined using the => syntax. They are a shorter way to write function expressions and do not have their own this value.
  2762. Question 189 What will be the output of the following JavaScript expression?
  2763.  
  2764. console.log(0.1 + 0.2 === 0.3);
  2765.  
  2766. A. true
  2767.  
  2768. B. false
  2769.  
  2770. C. TypeError
  2771.  
  2772. D. undefined
  2773.  
  2774. Answer: B. false
  2775.  
  2776. Explanation: Due to the way JavaScript handles floating-point arithmetic, the result of 0.1 + 0.2 is not exactly 0.3. Therefore, this comparison returns false.
  2777. Question 190 In JavaScript, what is the use of the splice method?
  2778.  
  2779. A. To join two arrays together.
  2780.  
  2781. B. To search for a specified value within an array.
  2782.  
  2783. C. To change the contents of an array by removing or replacing existing elements and/or adding new elements.
  2784.  
  2785. D. To split a string into an array of substrings.
  2786.  
  2787. Answer: C. To change the contents of an array by removing or replacing existing elements and/or adding new elements.
  2788.  
  2789. Explanation: The splice method in JavaScript is used to change the contents of an array by removing, replacing, and/or adding new elements in place.
  2790. Question 191 What will the following JavaScript code output?
  2791.  
  2792. console.log(typeof undefined);
  2793.  
  2794. A. “undefined
  2795.  
  2796. B. “object”
  2797.  
  2798. C. “null
  2799.  
  2800. D. “string”
  2801.  
  2802. Answer: A. “undefined
  2803.  
  2804. Explanation: The typeof operator when used with undefined will return the string “undefined”.
  2805. Question 192 What does the === operator check in JavaScript?
  2806.  
  2807. A. Only the value equality
  2808.  
  2809. B. Only the type equality
  2810.  
  2811. C. Both value and type equality
  2812.  
  2813. D. The existence of variables
  2814.  
  2815. Answer: C. Both value and type equality
  2816.  
  2817. Explanation: The === operator, also known as the strict equality operator, checks both the value and the type of the operands, making sure they are identical.
  2818. Question 193 How can a for loop be stopped in JavaScript?
  2819.  
  2820. A. stop();
  2821.  
  2822. B. break;
  2823.  
  2824. C. exit;
  2825.  
  2826. D. terminate;
  2827.  
  2828. Answer: B. break;
  2829.  
  2830. Explanation: The break statement is used to exit from a loop before it has looped through all its items.
  2831. Question 194 Which of the following is a way to define a constant in JavaScript?
  2832.  
  2833. A. var CONSTANT_NAME = value;
  2834.  
  2835. B. let CONSTANT_NAME = value;
  2836.  
  2837. C. const CONSTANT_NAME = value;
  2838.  
  2839. D. #define CONSTANT_NAME value
  2840.  
  2841. Answer: C. const CONSTANT_NAME = value;
  2842.  
  2843. Explanation: The const keyword is used to define a constant in JavaScript. A constant cannot be reassigned after its declaration.
  2844. Question 195 What is the output of the following code?
  2845.  
  2846. let x = 10;
  2847.  
  2848. let y =10;
  2849.  
  2850. console.log(x === y);
  2851.  
  2852. A. true
  2853.  
  2854. B. false
  2855.  
  2856. C. TypeError
  2857.  
  2858. D. undefined
  2859.  
  2860. Answer: B. false
  2861.  
  2862. Explanation: The === operator checks for both value and type equality. In this case, x is a number and y is a string, so the comparison returns false.
  2863. Question 196 Which method is used to add new items to the beginning of an array in JavaScript?
  2864.  
  2865. A. push()
  2866.  
  2867. B. pop()
  2868.  
  2869. C. unshift()
  2870.  
  2871. D. shift()
  2872.  
  2873. Answer: C. unshift()
  2874.  
  2875. Explanation: The unshift() method is used to add one or more elements to the beginning of an array and returns the new length of the array.
  2876. Question 197 What is the purpose of the Array.prototype.reduce() method in JavaScript?
  2877.  
  2878. A. To execute a reducer function on each element of the array, resulting in a single output value.
  2879.  
  2880. B. To combine all elements of an array into a single string.
  2881.  
  2882. C. To iterate over each element of an array.
  2883.  
  2884. D. To modify each element in the array and create a new array.
  2885.  
  2886. Answer: A. To execute a reducer function on each element of the array, resulting in a single output value.
  2887.  
  2888. Explanation: Array.prototype.reduce() applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.
  2889. Question 198 Which of the following will correctly call a function named myFunction?
  2890.  
  2891. A. call myFunction();
  2892.  
  2893. B. myFunction();
  2894.  
  2895. C. call function myFunction();
  2896.  
  2897. D. execute myFunction();
  2898.  
  2899. Answer: B. myFunction();
  2900.  
  2901. Explanation: In JavaScript, you call a function by writing the function’s name followed by parentheses. So, myFunction(); is the correct syntax.
  2902. Question 199 What will the following JavaScript code output?
  2903.  
  2904. let num =10;
  2905.  
  2906. console.log(typeof parseInt(num));
  2907.  
  2908. A. “number”
  2909.  
  2910. B. “string”
  2911.  
  2912. C. “object”
  2913.  
  2914. D. “undefined
  2915.  
  2916. Answer: A. “number”
  2917.  
  2918. Explanation: parseInt(num) converts the string “10” to the number 10. The typeof operator then returns “number”.
  2919. Question 200 In JavaScript, how is a while loop started?
  2920.  
  2921. A. while (condition) {}
  2922.  
  2923. B. while condition {}
  2924.  
  2925. C. while loop (condition) {}
  2926.  
  2927. D. while: (condition) {}
  2928.  
  2929. Answer: A. while (condition) {}
  2930.  
  2931. Explanation: A while loop in JavaScript is written with the syntax while (condition) {}, where the code inside the braces is executed as long as the condition evaluates to true.
  2932.  
  2933. These questions cover a variety of JavaScript topics, testing fundamental knowledge as well as more complex concepts.
  2934. Question 201 What is the output of the following JavaScript code?
  2935.  
  2936. let a =5;
  2937.  
  2938. let b = 5;
  2939.  
  2940. console.log(a === b);
  2941.  
  2942. A. true
  2943.  
  2944. B. false
  2945.  
  2946. C. TypeError
  2947.  
  2948. D. undefined
  2949.  
  2950. Answer: B. false
  2951.  
  2952. Explanation: The strict equality operator (===) checks both the value and the type of the operands. In this case, a is a string and b is a number, so the comparison returns false.
  2953. Question 202 Which of the following methods is used to remove an element from the end of an array in JavaScript?
  2954.  
  2955. A. shift()
  2956.  
  2957. B. pop()
  2958.  
  2959. C. push()
  2960.  
  2961. D. unshift()
  2962.  
  2963. Answer: B. pop()
  2964.  
  2965. Explanation: The pop() method removes the last element from an array and returns that element. This alters the length of the array.
  2966. Question 203 How do you declare a JavaScript variable that cannot be reassigned?
  2967.  
  2968. A. var variableName = value;
  2969.  
  2970. B. let variableName = value;
  2971.  
  2972. C. const variableName = value;
  2973.  
  2974. D. immutable variableName = value;
  2975.  
  2976. Answer: C. const variableName = value;
  2977.  
  2978. Explanation: The const keyword is used to declare a JavaScript variable that cannot be reassigned after it’s been declared.
  2979. Question 204 In JavaScript, what will the following expression return?
  2980.  
  2981. typeof NaN
  2982.  
  2983. A. “number”
  2984.  
  2985. B. “NaN
  2986.  
  2987. C. “undefined
  2988.  
  2989. D. “object”
  2990.  
  2991. Answer: A. “number”
  2992.  
  2993. Explanation: NaN (Not a Number) in JavaScript is considered a numeric value, and thus typeof NaN returns “number”.
  2994. Question 205 What is the purpose of the Array.prototype.map() method in JavaScript?
  2995.  
  2996. A. To execute a function on each element in the array and return a new array.
  2997.  
  2998. B. To combine all elements of an array into a single value.
  2999.  
  3000. C. To filter elements based on a condition and return a new array.
  3001.  
  3002. D. To check if at least one element in the array passes a test.
  3003.  
  3004. Answer: A. To execute a function on each element in the array and return a new array.
  3005.  
  3006. Explanation: Array.prototype.map() creates a new array with the results of calling a provided function on every element in the calling array.
  3007. Question 206 What does the following JavaScript code output?
  3008.  
  3009. console.log(“Hello” || “World”);
  3010.  
  3011. console.log(“Foo” && “Bar”);
  3012.  
  3013. A. “Hello” and “Foo”
  3014.  
  3015. B. “World” and “Bar”
  3016.  
  3017. C. “Hello” and “Bar”
  3018.  
  3019. D. “World” and “Foo”
  3020.  
  3021. Answer: C. “Hello” and “Bar”
  3022.  
  3023. Explanation: The logical OR (||) operator returns the first truthy operand, which is “Hello”. The logical AND (&&) operator returns the second operand if the first is truthy, which in this case is “Bar”.
  3024. Question 207 Which of the following is a correct syntax for creating a new object in JavaScript?
  3025.  
  3026. A. let obj = new Object();
  3027.  
  3028. B. let obj = {};
  3029.  
  3030. C. let obj = Object.create(null);
  3031.  
  3032. D. All of the above
  3033.  
  3034. Answer: D. All of the above
  3035.  
  3036. Explanation: All three methods are correct ways to create a new object in JavaScript. new Object() and {} (object literal syntax) are more common, whereas Object.create(null) is used for more complex cases, like creating an object without a prototype.
  3037. Question 208 What is the correct way to write a JavaScript array?
  3038.  
  3039. A. let arr = new Array(“item1”, “item2”, “item3”);
  3040.  
  3041. B. let arr = [“item1”, “item2”, “item3”];
  3042.  
  3043. C. let arr = Array(“item1”, “item2”, “item3”);
  3044.  
  3045. D. All of the above
  3046.  
  3047. Answer: D. All of the above
  3048.  
  3049. Explanation: All three statements are valid ways to create an array in JavaScript. new Array() and Array() are constructor syntaxes, while [] is array literal syntax.
  3050. Question 209 In JavaScript, how can you catch errors thrown during asynchronous operations?
  3051.  
  3052. A. Using a trycatch block.
  3053.  
  3054. B. Using a catch() method on a promise.
  3055.  
  3056. C. Using an onError event handler.
  3057.  
  3058. D. Both A and B
  3059.  
  3060. Answer: D. Both A and B
  3061.  
  3062. Explanation: For asynchronous operations, errors can be caught using catch() method on a promise. Additionally, with the async/await syntax
  3063. Question 210 What will the following JavaScript code output?
  3064.  
  3065. console.log(1 +1);
  3066.  
  3067. A. 11
  3068.  
  3069. B. 2
  3070.  
  3071. C. “11
  3072.  
  3073. D. undefined
  3074.  
  3075. Answer: C. “11
  3076.  
  3077. Explanation: When you use the + operator with a string and a number, JavaScript performs type coercion and converts the number to a string before concatenating them.
  3078. Question 211 Which JavaScript method is used to join the elements of an array into a string with a specified separator?
  3079.  
  3080. A. join()
  3081.  
  3082. B. concat()
  3083.  
  3084. C. split()
  3085.  
  3086. D. merge()
  3087.  
  3088. Answer: A. join()
  3089.  
  3090. Explanation: The join() method in JavaScript is used to join the elements of an array into a string with a specified separator.
  3091. Question 212 What is the purpose of the Array.prototype.filter() method in JavaScript?
  3092.  
  3093. A. To execute a function on each element in the array and return a new array.
  3094.  
  3095. B. To combine all elements of an array into a single value.
  3096.  
  3097. C. To filter elements based on a condition and return a new array.
  3098.  
  3099. D. To check if at least one element in the array passes a test.
  3100.  
  3101. Answer: C. To filter elements based on a condition and return a new array.
  3102.  
  3103. Explanation: Array.prototype.filter() creates a new array with all elements that pass the test implemented by the provided function.
  3104. Question 213 In JavaScript, how do you declare a multi-line string?
  3105.  
  3106. A. Use backticks (`) and template literals.
  3107.  
  3108. B. Use double quotes () with line breaks.
  3109.  
  3110. C. Use single quotes () with line breaks.
  3111.  
  3112. D. JavaScript does not support multi-line strings.
  3113.  
  3114. Answer: A. Use backticks (`) and template literals.
  3115.  
  3116. Explanation: In JavaScript, you can declare multi-line strings using backticks (`) and template literals. This allows you to include line breaks within the string.
  3117. Question 214 What is the purpose of the Array.prototype.forEach() method in JavaScript?
  3118.  
  3119. A. To execute a function on each element in the array and return a new array.
  3120.  
  3121. B. To combine all elements of an array into a single value.
  3122.  
  3123. C. To iterate over each element of an array and apply a function.
  3124.  
  3125. D. To check if at least one element in the array passes a test.
  3126.  
  3127. Answer: C. To iterate over each element of an array and apply a function.
  3128.  
  3129. Explanation: Array.prototype.forEach() is used to iterate over each element of an array and apply a function to each element without creating a new array.
  3130. Question 215 What will the following JavaScript code output?
  3131.  
  3132. console.log(3 === 3 && 4 !== 5);
  3133.  
  3134. A. true
  3135.  
  3136. B. false
  3137.  
  3138. C. TypeError
  3139.  
  3140. D. undefined
  3141.  
  3142. Answer: A. true
  3143.  
  3144. Explanation: The && operator performs a logical AND operation. Both conditions 3 === 3 (true) and 4 !== 5 (true) are satisfied, so the result is true.
  3145. Question 216 In JavaScript, which of the following statements is used to skip the current iteration of a loop and continue with the next one?
  3146.  
  3147. A. break
  3148.  
  3149. B. continue
  3150.  
  3151. C. return
  3152.  
  3153. D. exit
  3154.  
  3155. Answer: B. continue
  3156.  
  3157. Explanation: The continue statement is used to skip the current iteration of a loop and continue with the next iteration.
  3158. Question 217 What is the purpose of the Array.prototype.indexOf() method in JavaScript?
  3159.  
  3160. A. To find the index of the first occurrence of a value in an array.
  3161.  
  3162. B. To sort the elements of an array.
  3163.  
  3164. C. To add an element to the end of an array.
  3165.  
  3166. D. To remove the last element from an array.
  3167.  
  3168. Answer: A. To find the index of the first occurrence of a value in an array.
  3169.  
  3170. Explanation: Array.prototype.indexOf() is used to find the index of the first occurrence of a specified value in an array.
  3171. Question 218 What is the output of the following JavaScript code?
  3172.  
  3173. let x = 5;
  3174.  
  3175. function myFunction() {
  3176.  
  3177.  let x = 10;
  3178.  
  3179.  console.log(x);
  3180.  
  3181. }
  3182.  
  3183. myFunction();
  3184.  
  3185. console.log(x);
  3186.  
  3187. A. 5 and 5
  3188.  
  3189. B. 10 and 5
  3190.  
  3191. C. 5 and 10
  3192.  
  3193. D. 10 and 10
  3194.  
  3195. Answer: B. 10 and 5
  3196.  
  3197. Explanation: Inside the myFunction function, there is a local variable x with a value of 10, which is different from the global variable x with a value of 5. So, the first console.log outputs 10, and the second console.log outputs 5.
  3198. Question 219 What does the isNaN() function in JavaScript do?
  3199.  
  3200. A. It checks if a value is not a string.
  3201.  
  3202. B. It checks if a value is not a number.
  3203.  
  3204. C. It checks if a value is not an array.
  3205.  
  3206. D. It checks if a value is not an object.
  3207.  
  3208. Answer: B. It checks if a value is not a number.
  3209.  
  3210. Explanation: The isNaN() function checks if a value is not a number and returns true if the value is not a number, false if it is a number.
  3211. Question 220 What is the result of the following JavaScript code?
  3212.  
  3213. console.log(2 + 2 +2);
  3214.  
  3215. A. 22
  3216.  
  3217. B. 42
  3218.  
  3219. C. 6
  3220.  
  3221. D. TypeError
  3222.  
  3223. Answer: A. 22
  3224.  
  3225. Explanation: JavaScript performs the addition from left to right, so 2 + 2 equals 4, and then “2” is concatenated to it, resulting in22”.
  3226. Question 221 Which keyword is used to declare a function in JavaScript?
  3227.  
  3228. A. function
  3229.  
  3230. B. def
  3231.  
  3232. C. func
  3233.  
  3234. D. method
  3235.  
  3236. Answer: A. function
  3237.  
  3238. Explanation: The function keyword is used to declare a function in JavaScript.
  3239. Question 222 What will the following JavaScript code output?
  3240.  
  3241. console.log(5” – 3);
  3242.  
  3243. A. 2
  3244.  
  3245. B. 8
  3246.  
  3247. C. “2
  3248.  
  3249. D. TypeError
  3250.  
  3251. Answer: A. 2
  3252.  
  3253. Explanation: JavaScript performs type coercion when using the – operator, so the string “5” is converted to a number, resulting in 53, which equals 2.
  3254. Question 223 In JavaScript, which of the following is used to create a new object with the same prototype as an existing object?
  3255.  
  3256. A. Object.assign()
  3257.  
  3258. B. Object.create()
  3259.  
  3260. C. Object.copy()
  3261.  
  3262. D. Object.clone()
  3263.  
  3264. Answer: B. Object.create()
  3265.  
  3266. Explanation: The Object.create() method is used to create a new object with the specified prototype object.
  3267. Question 224 What is the purpose of the Array.prototype.reduce() method in JavaScript?
  3268.  
  3269. A. To execute a reducer function on each element of the array, resulting in a single output value.
  3270.  
  3271. B. To combine all elements of an array into a single string.
  3272.  
  3273. C. To iterate over each element of an array.
  3274.  
  3275. D. To filter elements based on a condition and return a new array.
  3276.  
  3277. Answer: A. To execute a reducer function on each element of the array, resulting in a single output value.
  3278.  
  3279. Explanation: Array.prototype.reduce() applies a function against an accumulator and each element in the array to reduce it to a single value.
  3280. Question 225 Which of the following statements is true about JavaScript variables declared with var inside a function?
  3281.  
  3282. A. They have block scope.
  3283.  
  3284. B. They are hoisted to the top of the function.
  3285.  
  3286. C. They cannot be reassigned.
  3287.  
  3288. D. They are block-scoped and not hoisted.
  3289.  
  3290. Answer: B. They are hoisted to the top of the function.
  3291.  
  3292. Explanation: Variables declared with var are hoisted to the top of their containing function, which means their declarations are processed before the code is executed.
  3293. Question 226 What is the output of the following JavaScript code?
  3294.  
  3295. console.log(10 / 0);
  3296.  
  3297. A. 10
  3298.  
  3299. B. 0
  3300.  
  3301. C. Infinity
  3302.  
  3303. D. NaN
  3304.  
  3305. Answer: C. Infinity
  3306.  
  3307. Explanation: Division by zero in JavaScript results in Infinity.
  3308. Question 227 In JavaScript, which loop is used for iterating over the properties of an object?
  3309.  
  3310. A. forin loop
  3311.  
  3312. B. for loop
  3313.  
  3314. C. while loop
  3315.  
  3316. D. do…while loop
  3317.  
  3318. Answer: A. forin loop
  3319.  
  3320. Explanation: The forin loop is used for iterating over the properties of an object.
  3321. Question 228 What is the purpose of the Array.prototype.includes() method in JavaScript?
  3322.  
  3323. A. To check if an element is included in an array.
  3324.  
  3325. B. To add an element to the beginning of an array.
  3326.  
  3327. C. To remove an element from an array.
  3328.  
  3329. D. To check if an array is empty.
  3330.  
  3331. Answer: A. To check if an element is included in an array.
  3332.  
  3333. Explanation: Array.prototype.includes() is used to check if a specified element is present in an array and returns true or false.
  3334. Question 229 What will the following JavaScript code output?
  3335.  
  3336. console.log(0.1 + 0.2 === 0.3);
  3337.  
  3338. A. true
  3339.  
  3340. B. false
  3341.  
  3342. C. TypeError
  3343.  
  3344. D. undefined
  3345.  
  3346. Answer: B. false
  3347.  
  3348. Explanation: Due to floating-point precision in JavaScript, 0.1 + 0.2 is not exactly equal to 0.3, so the comparison returns false.
  3349. Question 230 What is the result of the following JavaScript code?
  3350.  
  3351. console.log(5+ 3);
  3352.  
  3353. A. 53
  3354.  
  3355. B. 8
  3356.  
  3357. C. “53
  3358.  
  3359. D. TypeError
  3360.  
  3361. Answer: A. 53
  3362.  
  3363. Explanation: When you use the + operator with a string and a number, JavaScript performs concatenation, so “5” is concatenated with 3, resulting in53”.
  3364. Question 231 Which of the following is a correct way to declare a JavaScript function?
  3365.  
  3366. A. function myFunction() {}
  3367.  
  3368. B. let myFunction() {}
  3369.  
  3370. C. const myFunction() {}
  3371.  
  3372. D. var myFunction() {}
  3373.  
  3374. Answer: A. function myFunction() {}
  3375.  
  3376. Explanation: The correct way to declare a JavaScript function is using the function keyword followed by the function name.
  3377. Question 232 What will the following JavaScript code output?
  3378.  
  3379. console.log(typeof “Hello”);
  3380.  
  3381. A. “string”
  3382.  
  3383. B. “object”
  3384.  
  3385. C. “null
  3386.  
  3387. D. “undefined
  3388.  
  3389. Answer: A. “string”
  3390.  
  3391. Explanation: The typeof operator when used with a string will return the string “string”.
  3392. Question 233 In JavaScript, which loop is used to execute a block of code at least once, and then repeatedly as long as a condition is true?
  3393.  
  3394. A. for loop
  3395.  
  3396. B. while loop
  3397.  
  3398. C. do…while loop
  3399.  
  3400. D. if statement
  3401.  
  3402. Answer: C. do…while loop
  3403.  
  3404. Explanation: The do…while loop is used to execute a block of code at least once, and then repeatedly as long as a condition is true.
  3405. Question 234 What is the purpose of the Array.prototype.concat() method in JavaScript?
  3406.  
  3407. A. To execute a function on each element in the array and return a new array.
  3408.  
  3409. B. To combine all elements of an array into a single string.
  3410.  
  3411. C. To merge two or more arrays and return a new array.
  3412.  
  3413. D. To check if an array is empty.
  3414.  
  3415. Answer: C. To merge two or more arrays and return a new array.
  3416.  
  3417. Explanation: Array.prototype.concat() is used to merge two or more arrays into a new array.
  3418. Question 235 What does the Math.random() function in JavaScript return?
  3419.  
  3420. A. A random integer between 0 and 1.
  3421.  
  3422. B. A random integer between 0 and 100.
  3423.  
  3424. C. A random floating-point number between 0 (inclusive) and 1 (exclusive).
  3425.  
  3426. D. A random floating-point number between 0 (inclusive) and 100 (exclusive).
  3427.  
  3428. Answer: C. A random floating-point number between 0 (inclusive) and 1 (exclusive).
  3429.  
  3430. Explanation: Math.random() returns a random floating-point number between 0 (inclusive) and 1 (exclusive).
  3431. Question 236 In JavaScript, which operator is used to test if a specific property exists in an object?
  3432.  
  3433. A. in
  3434.  
  3435. B. exists
  3436.  
  3437. C. has
  3438.  
  3439. D. check
  3440.  
  3441. Answer: A. in
  3442.  
  3443. Explanation: The in operator is used to test if a specific property exists in an object.
  3444. Question 237 What is the output of the following JavaScript code?
  3445.  
  3446. let x = 10;
  3447.  
  3448. let y = 5;
  3449.  
  3450. console.log(x > y ? “x is greater” : “y is greater”);
  3451.  
  3452. A. “x is greater”
  3453.  
  3454. B. “y is greater”
  3455.  
  3456. C. “x > y ? “x is greater” : “y is greater”
  3457.  
  3458. D. TypeError
  3459.  
  3460. Answer: A. “x is greater”
  3461.  
  3462. Explanation: This is a ternary conditional expression. It checks if x is greater than y and, if true, returns “x is greater”, otherwise, it returns “y is greater”.
  3463. Question 238 What is the purpose of the Array.prototype.slice() method in JavaScript?
  3464.  
  3465. A. To execute a function on each element in the array and return a new array.
  3466.  
  3467. B. To remove the last element from an array.
  3468.  
  3469. C. To create a shallow copy of an array containing a portion of the original array.
  3470.  
  3471. D. To check if an array is empty.
  3472.  
  3473. Answer: C. To create a shallow copy of an array containing a portion of the original array.
  3474.  
  3475. Explanation: Array.prototype.slice() is used to create a shallow copy of an array containing a portion of the original array.
  3476. Question 239 What will the following JavaScript code output?
  3477.  
  3478. let x = 5;
  3479.  
  3480. let y =5;
  3481.  
  3482. console.log(x == y);
  3483.  
  3484. A. true
  3485.  
  3486. B. false
  3487.  
  3488. C. TypeError
  3489.  
  3490. D. undefined
  3491.  
  3492. Answer: A. true
  3493.  
  3494. Explanation: The == operator performs type coercion, so it converts the string “5” to a number and then checks for equality, which is true.
  3495. Question 240 What will the following JavaScript code output?
  3496.  
  3497. console.log(3 *2);
  3498.  
  3499. A. 6
  3500.  
  3501. B. “6
  3502.  
  3503. C. 32
  3504.  
  3505. D. TypeError
  3506.  
  3507. Answer: A. 6
  3508.  
  3509. Explanation: JavaScript performs type coercion, so the string “2” is converted to a number, and then the multiplication 3 * 2 results in 6.
  3510. Question 241 Which of the following is the correct way to comment out a single line of JavaScript code?
  3511.  
  3512. A. /* This is a comment */
  3513.  
  3514. B. <!– This is a comment –>
  3515.  
  3516. C. # This is a comment
  3517.  
  3518. D. // This is a comment
  3519.  
  3520. Answer: D. // This is a comment
  3521.  
  3522. Explanation: In JavaScript, you can use // to comment out a single line of code.
  3523. Question 242 In JavaScript, what is the purpose of the break statement?
  3524.  
  3525. A. To declare a variable.
  3526.  
  3527. B. To exit a loop or switch statement prematurely.
  3528.  
  3529. C. To add an element to an array.
  3530.  
  3531. D. To remove an element from an array.
  3532.  
  3533. Answer: B. To exit a loop or switch statement prematurely.
  3534.  
  3535. Explanation: The break statement is used to exit a loop or switch statement prematurely.
  3536. Question 243 What will the following JavaScript code output?
  3537.  
  3538. let str = “Hello, World!;
  3539.  
  3540. console.log(str.length);
  3541.  
  3542. A. 5
  3543.  
  3544. B. 7
  3545.  
  3546. C. 12
  3547.  
  3548. D. 13
  3549.  
  3550. Answer: D. 13
  3551.  
  3552. Explanation: The str.length property returns the length of the string, which is 13 characters in this case.
  3553. Question 244 Which of the following statements is true about JavaScript’s null value?
  3554.  
  3555. A. null is a number.
  3556.  
  3557. B. null represents an empty string.
  3558.  
  3559. C. null represents the absence of a value or an empty object.
  3560.  
  3561. D. null is the same as undefined.
  3562.  
  3563. Answer: C. null represents the absence of a value or an empty object.
  3564.  
  3565. Explanation: null in JavaScript represents the absence of a value or an empty object. It is not a number or an empty string.
  3566. Question 245 What is the purpose of the Array.prototype.unshift() method in JavaScript?
  3567.  
  3568. A. To execute a function on each element in the array and return a new array.
  3569.  
  3570. B. To add a new element to the end of an array.
  3571.  
  3572. C. To add one or more elements to the beginning of an array and return the new length.
  3573.  
  3574. D. To remove the first element from an array.
  3575.  
  3576. Answer: C. To add one or more elements to the beginning of an array and return the new length.
  3577.  
  3578. Explanation: Array.prototype.unshift() adds one or more elements to the beginning of an array and returns the new length of the array.
  3579. Question 246 What is the output of the following JavaScript code?
  3580.  
  3581. console.log(“Hello” + 5 + 3);
  3582.  
  3583. A. Hello8
  3584.  
  3585. B. Hello53
  3586.  
  3587. C. Hello15
  3588.  
  3589. D. TypeError
  3590.  
  3591. Answer: B. Hello53
  3592.  
  3593. Explanation: JavaScript performs concatenation from left to right, so “Hello” + 5 results in “Hello5”, and then “Hello5” + 3 results in “Hello53”.
  3594. Question 247 In JavaScript, how can you check if a variable is an array?
  3595.  
  3596. A. Using the typeof operator.
  3597.  
  3598. B. Using the isArray() method.
  3599.  
  3600. C. Using the isArray property.
  3601.  
  3602. D. Using the array keyword.
  3603.  
  3604. Answer: B. Using the isArray() method.
  3605.  
  3606. Explanation: You can use the Array.isArray() method to check if a variable is an array in JavaScript.
  3607. Question 248 What will the following JavaScript code output?
  3608.  
  3609. let x = 5;
  3610.  
  3611. let y = 10;
  3612.  
  3613. console.log(x > y ? “x is greater” : “y is greater”);
  3614.  
  3615. A. “x is greater”
  3616.  
  3617. B. “y is greater”
  3618.  
  3619. C. “x > y ? “x is greater” : “y is greater”
  3620.  
  3621. D. TypeError
  3622.  
  3623. Answer: B. “y is greater”
  3624.  
  3625. Explanation: This is a ternary conditional expression. It checks if x is greater than y, which is false, so it returns “y is greater”.
  3626. Question 249 What is the purpose of the Array.prototype.reverse() method in JavaScript?
  3627.  
  3628. A. To execute a function on each element in the array and return a new array.
  3629.  
  3630. B. To reverse the order of elements in an array in place.
  3631.  
  3632. C. To sort the elements of an array.
  3633.  
  3634. D. To check if an array is empty.
  3635.  
  3636. Answer: B. To reverse the order of elements in an array in place.
  3637.  
  3638. Explanation: Array.prototype.reverse() is used to reverse the order of elements in an array in place, without creating a new array.
  3639. Question 250 What is the purpose of the Array.prototype.every() method in JavaScript?
  3640.  
  3641. A. To execute a function on each element in the array and return a new array.
  3642.  
  3643. B. To combine all elements of an array into a single value.
  3644.  
  3645. C. To check if at least one element in the array passes a test.
  3646.  
  3647. D. To check if all elements in the array pass a test.
  3648.  
  3649. Answer: D. To check if all elements in the array pass a test.
  3650.  
  3651. Explanation: Array.prototype.every() is used to check if all elements in an array pass a test implemented by a provided function. It returns true if all elements pass the test, otherwise, it returns false.
  3652. JavaScript-Quiz-and-SolutionsDownload
  3653. Share this:
  3654.  
  3655.  
Tags: js
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement