C

Chandani • 9.82K Points
Tutor III

Q. What will be the output of the following JavaScript code?

Code:
// JavaScript Comparison Operators
function compare()
{
    let a=2;
    let b=2.0;
    if(a==b)
        return true;
    else
        return false;
}
  • (A) false
  • (B) true
  • (C) compilation error
  • (D) runtime error
  • Correct Answer - Option(B)
  • Views: 74
  • Filed under category JavaScript

Explanation by: Chandani
The == in JS convert different types of operands to the same type before making the comparison whereas a strict comparison === results in true value if the operands are of the same type and the contents match.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics