Borja Borja -3 years ago 96
Javascript Question

Why return function with arguments is undefined?

I tried for many hours but I don't understand why

return
is undefined...

This is my code:

var x = 30.858;
var id = 584;

var num_reg = region(x);
if (num_reg == false) {
num_reg = ripeti_region(x);
}


function ripeti_region(lng) {
if (lng <= 180) {
lng = lng - 0.2;
} else if (lng => -180) {
lng = lng + 0.2;
}

if (region(lng) != false) {
var x = region(lng);
return x;
} else {
ripeti_region(lng);
}
}


function region(lng) {
if (lng <= 30.458) {
return id;
} else {
return false;
}
}


alert(num_reg);


If I alert
num_reg
I have undefined return, but the code works in fact in function
ripeti_region(lng)
if you add
alert(x)
it prints
var id


So I would that
num_reg
give like output
var id
value.

This is jsfiddle:
https://jsfiddle.net/nj4duw61/

Answer Source

Your problem is here:

else {
    ripeti_region(lng);
  }

This part of code doesn't return anything.

Probably you wanted to return ripeti_region(lng);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download