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
πŸ’¬ Discuss
βœ… Correct Answer: (B) true
Explanation: 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.
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
173
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Chandani
Publisher
πŸ“ˆ
94%
Success Rate