JavaScript

What is the output of the following code: console.log([…”Hello”]);?

What is the output of the following code: console.log([…”Hello”]);? a) ["H", "e", "l", "l", "o"] b) "Hello" c) [["H", "e", "l", "l", "o"]] d) undefined Answer: a) ["H", "e", "l", "l", "o"] Explanation: The spread operator (…) spreads the elements of an iterable (like a string) into individual elements. When applied to the string "Hello",

What is the output of the following code: console.log([…”Hello”]);? Read More »

What is the difference between Object.freeze() and Object.seal() in JavaScript?

What is the difference between Object.freeze() and Object.seal() in JavaScript? a) Object.freeze() makes an object immutable, while Object.seal() prevents new properties from being added b) Object.freeze() allows new properties, while Object.seal() does not c) Object.seal() removes properties, while Object.freeze() adds properties d) They are identical Answer: a) Object.freeze() makes an object immutable, while Object.seal() prevents

What is the difference between Object.freeze() and Object.seal() in JavaScript? Read More »

How do you create a deep copy of an object in JavaScript?

How do you create a deep copy of an object in JavaScript? a) JSON.parse(JSON.stringify(object)) b) Object.assign() c) object.slice() d) Array.map() Answer: a) JSON.parse(JSON.stringify(object)) Explanation: To create a deep copy of an object in JavaScript, you can use JSON.parse(JSON.stringify(object)). This method works by first converting the object into a JSON string and then parsing it back

How do you create a deep copy of an object in JavaScript? Read More »

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

What is the output of the following code: console.log(typeof function(){});? a) "object" b) "function" c) "undefined" d) "object function" Answer: b) "function" Explanation: In JavaScript, the typeof operator returns "function" when applied to a function. Functions in JavaScript are a special type of object, but typeof identifies them as "function". Reference: JavaScript MCQ (Multiple-Choice Questions)

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

What is the difference between call() and apply() methods in JavaScript?

What is the difference between call() and apply() methods in JavaScript? a) call() takes individual arguments, while apply() takes an array of arguments b) call() is used for synchronous code, while apply() is used for asynchronous code c) call() executes a function immediately, while apply() creates a promise d) Both are identical Answer: a) call()

What is the difference between call() and apply() methods in JavaScript? Read More »

What will the console.log([1, 2, 3] + [4, 5, 6]) statement output?

What will the console.log([1, 2, 3] + [4, 5, 6]) statement output? a) "1,2,34,5,6" b) "1,2,3,4,5,6" c) [1,2,3,4,5,6] d) NaN Answer: a) "1,2,34,5,6" Explanation: In JavaScript, when you use the + operator with arrays, it converts the arrays to strings and concatenates them. Therefore, the result is "1,2,34,5,6", a concatenated string of the two arrays.

What will the console.log([1, 2, 3] + [4, 5, 6]) statement output? Read More »

Scroll to Top