What will be the output of the following JavaScript code? [code] function compare() { int a=1; char b=1; if(a.tostring()===b)

What will be the output of the following JavaScript code?
Code:
function compare()
{
    int a=1;
    char b=1;
    if(a.tostring()===b)
        return true;
    else 
        return false;
}
A. true
B. false
C. runtime error
D. logical error
 
Answer: a
Explanation: A non string (integer) can be converted to string using .tostring() function. A strict comparison is only true if the operands are of the same type and the contents match. Hence the following code snippet would result into true output.
 

Tìm kiếm

Back
Top