zelocalhost
zelocalhost

Reputation: 1183

How to use the return true/false in js

I have a function, for example check navigator params, like that :

function paramsDevice() { 
    if ( navigator.userAgent. etc ... ) {
        return true;
    } else {
        return false;
    }
}

how to use the return, in a other part of js code ?

if (paramsDevice == false)

not working and i have no error

Upvotes: 1

Views: 61

Answers (2)

potashin
potashin

Reputation: 44581

In your code you are comparing undefined variable paramsDevice with the boolean false.To compare returned by paramsDevice() value try the following :

if (paramsDevice() == false)

You can also assign a variable to the result to use it in the if statement :

var paramsDevice = paramsDevice()
if (paramsDevice == false)

Upvotes: 2

underscore
underscore

Reputation: 6877

use === to compare with false .You can assign your function a variable.Then you can check the variable if (paramsDevice == false)

var paramsDevice = function() {
    if (1 === true) {
        return true;
    } else {
        return false;
    }
};


if (paramsDevice === false) {
alert('working....');
}

WORKING Demo

Upvotes: 1

Related Questions