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 comparison is true.

Example:


console.log(5 == "5"); // Output: true
console.log(5 === "5"); // Output: false (strict equality without type coercion)
    

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top