in this code this method return undefined despites alert statement print a value ?
function getNearestPoint(idd)
{
var xmlhttp;
result setting statement executes inside async Ajax functionBecause your second if statement (that sets result value) doesn't get hit. Why not? Because the moment you send an Ajax request you return the result value which is still undefined. Ajax call will execute the anonymous function later on and set this result variable which has been returned long ago.