Skip to content Skip to sidebar Skip to footer

Why Is This Javascript Function Returning Undefined ?

let getLowerUpperBoundFromValue=(bound , idToValue)=>{ // Returns the value of the variable previously generated if 'value' is a variable name or return 'value' if its

Solution 1:

Nothing is returning because the forEach callback is a seperate method. I removed the call to .forEach and replaced it with a for of loop which maintains scope for the return

let getLowerUpperBoundFromValue=(bound , idToValue)=>{
        // Returns the value of the variable previously generated if "value" is a variable name  or return "value" if its a number . 
        // bound :  can be a direct integer or a variable name. 
        // idToValue : contains the id to value mapping which must contain a variable whose name must be equal to 'bound' parameter if its a variable name . 

        if(isNaN(Number(bound)))
        {
            for (let idStatePair of Object.entries(idToVarStatesGlobal)) {
                let id= idStatePair[0] , varState = idStatePair[1] ; 
                if(varState.name===bound){
                    console.log("check now Returning idTovalue[id]" , idToValue , id , idToValue[id] , Number(idToValue[id]));
                    return Number(idToValue[id]) ; 
                }
            }
        }
        else return Number(bound); 
    }

Post a Comment for "Why Is This Javascript Function Returning Undefined ?"