JavaScript

Which method is used to convert JSON data to a JavaScript object?

Which method is used to convert JSON data to a JavaScript object? a) JSON.parse() b) JSON.stringify() c) Object.assign() d) Array.from() Answer: a) JSON.parse() Explanation: The JSON.parse() method is used to convert a JSON string into a JavaScript object. This is commonly used when receiving JSON data from an API or another external source. Reference: JavaScript […]

Which method is used to convert JSON data to a JavaScript object? Read More »

What is the output of the following code: console.log(typeof NaN);?

What is the output of the following code: console.log(typeof NaN);? a) "undefined" b) "number" c) "object" d) "NaN" Answer: b) "number" Explanation: In JavaScript, NaN stands for “Not-a-Number”, but it is still considered a numeric value. When checking the type of NaN using typeof, the result is "number". Reference: JavaScript MCQ (Multiple-Choice Questions)

What is the output of the following code: console.log(typeof NaN);? Read More »

Which of the following will correctly check if a variable is an array in JavaScript?

Which of the following will correctly check if a variable is an array in JavaScript? a) Array.isArray(variable) b) typeof variable === 'array' c) variable.isArray() d) variable instanceof Object Answer: a) Array.isArray(variable) Explanation: The most reliable way to check if a variable is an array in JavaScript is by using Array.isArray(variable). This method returns true if

Which of the following will correctly check if a variable is an array in JavaScript? Read More »

What will the console.log(0.1 + 0.2 === 0.3) statement output?

What will the console.log(0.1 + 0.2 === 0.3) statement output? a) true b) false c) undefined d) NaN Answer: b) false Explanation: In JavaScript, the expression 0.1 + 0.2 === 0.3 evaluates to false due to floating-point precision issues. JavaScript uses floating-point arithmetic, which cannot precisely represent some decimal numbers, leading to small errors in

What will the console.log(0.1 + 0.2 === 0.3) statement output? Read More »

Which of the following methods is used to find the index of an element in an array in JavaScript?

Which of the following methods is used to find the index of an element in an array in JavaScript? a) indexOf() b) findIndex() c) find() d) search() Answer: a) indexOf() Explanation: The indexOf() method returns the first index at which a given element can be found in an array, or -1 if the element is

Which of the following methods is used to find the index of an element in an array in JavaScript? Read More »

Which of the following is true about the this keyword in JavaScript arrow functions?

Which of the following is true about the this keyword in JavaScript arrow functions? a) this refers to the global object b) this is lexically bound c) this refers to the parent function’s scope d) this is dynamically bound Answer: b) this is lexically bound Explanation: In arrow functions, the this keyword is lexically bound,

Which of the following is true about the this keyword in JavaScript arrow functions? Read More »

What will the console.log(null == undefined) statement output?

What will the console.log(null == undefined) statement output? a) true b) false c) undefined d) NaN Answer: a) true Explanation: In JavaScript, null and undefined are loosely equal (==), meaning they are treated as the same value in non-strict comparison, so null == undefined returns true. However, they are not strictly equal (===), as their

What will the console.log(null == undefined) statement output? Read More »

Which of the following statements will result in true when using the strict equality operator (===)?

Which of the following statements will result in true when using the strict equality operator (===)? a) 5 === "5" b) null === undefined c) true === 1 d) 5 === 5 Answer: d) 5 === 5 Explanation: The strict equality operator (===) compares both the value and type of two variables. The statement 5

Which of the following statements will result in true when using the strict equality operator (===)? Read More »

Which of the following methods is used to remove the last element from an array in JavaScript?

Which of the following methods is used to remove the last element from an array in JavaScript? a) pop() b) shift() c) splice() d) remove() Answer: a) pop() Explanation: The pop() method is used to remove the last element from an array in JavaScript. It modifies the original array and returns the removed element. Example:

Which of the following methods is used to remove the last element from an array in JavaScript? Read More »

What does the typeof operator return for an undefined variable?

What does the typeof operator return for an undefined variable? a) “undefined” b) “null” c) “object” d) “number” Answer: a) “undefined” Explanation: The typeof operator in JavaScript returns the string “undefined” when used on a variable that has not been assigned a value. This is different from null, which is an object. For example: let

What does the typeof operator return for an undefined variable? Read More »

Scroll to Top