Boolean variable returns as string from javascript function [duplicate]

You don't declare the status status variable.

Therefore, the global one (window.status) is overwritten.

However, the HTML 5 spec defines that property as a DOMString:

interface Window : EventTarget {
  attribute DOMString status;
};

Therefore, it has a setter (either exposed or internal) which stores the stringified value.

To fix it, just declare your local variable using the var statement.


$( document ).ready(function(){
    $('#result').text(typeof validate());
    $('#result2').text(typeof validate2());
});

function validate(){
    var status = true;
    status = false;
    return status;
}
    
function validate2(){
    return true;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>Hello</p>
<div id="result"></div>
<div id="result2"></div>

EDIT: I was building the answer and something go wrong, anyway, the reason is explained well by @Oriol: The global window.status variable is the one which has the string value type.