Reputation: 1183
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
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
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....');
}
Upvotes: 1