JavaScript

How do you convert a string to an integer in JavaScript?

How do you convert a string to an integer in JavaScript? a) parseInt() b) parseFloat() c) Number() d) toString() Answer: a) parseInt() Explanation: The parseInt() function converts a string to an integer by parsing the string and returning the first integer value found. If the string does not contain a number, NaN (Not-a-Number) is returned. […]

How do you convert a string to an integer in JavaScript? Read More »

How do you check if a variable is an array in JavaScript?

How do you check if a variable is an array in JavaScript? a) Array.isArray(variable) b) variable.isArray() c) typeof variable === “array” d) variable instanceof Array Answer: a) Array.isArray(variable) Explanation: The method Array.isArray() is used to determine whether a variable is an array. It returns true if the variable is an array, and false otherwise. Example:

How do you check if a variable is an array in JavaScript? Read More »

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

What is the output of the following code: console.log(typeof null);? a) “object” b) “null” c) “undefined” d) “boolean” Answer: a) “object” Explanation: In JavaScript, the typeof operator returns “object” when applied to null. This is considered a quirk in JavaScript, as null is generally treated as a separate data type. Example: console.log(typeof null); // Output:

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

What is the output of the following code: console.log(5 == “5”);?

What is the output of the following code: console.log(5 == “5”);? a) true b) false c) NaN d) undefined Answer: a) true Explanation: In JavaScript, the double equals == performs type coercion, meaning it converts the operands to the same type before comparing. Here, "5" (a string) is converted to 5 (a number), so the

What is the output of the following code: console.log(5 == “5”);? Read More »

What is the output of the following code: console.log(“5” + 5);?

What is the output of the following code: console.log(“5” + 5);? a) “55” b) 10 c) NaN d) 5 Answer: a) “55” Explanation: When you use the + operator between a string and a number, JavaScript performs string concatenation. In this case, “5” (a string) is concatenated with 5 (a number), resulting in “55” (a

What is the output of the following code: console.log(“5” + 5);? Read More »

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

What is the output of the following code: console.log(typeof 42);? a) “number” b) “string” c) “boolean” d) “undefined” Answer: a) “number” Explanation: The typeof operator is used to determine the data type of a given variable or value in JavaScript. In this case, 42 is a number, so the output is “number”. Example: console.log(typeof 42);

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

Which of the following is used to output data to the browser console in JavaScript?

Which of the following is used to output data to the browser console in JavaScript? a) console.output() b) console.log() c) output.console() d) browser.log() Answer: b) console.log() Explanation: To output data to the browser’s console, you use the console.log() method in JavaScript. This is useful for debugging and displaying information during development. Example: console.log("Hello, World!"); Reference:

Which of the following is used to output data to the browser console in JavaScript? Read More »

What is JavaScript?

What is JavaScript? a) A programming language for web development b) A type of hardware c) A database language d) A styling language Answer: a) A programming language for web development Explanation: JavaScript is a popular programming language used primarily for web development. It allows developers to create dynamic content and interactive elements in web

What is JavaScript? Read More »

Scroll to Top