Bring the return of a function to a variable of another function

3

I would like to see if there is any way to do this:

function trazerNumero(){
    return 7;
}

function mostrarNumero(){
    numero = trazerNumero();
    alert(numero);
}



$(function(){
    mostrarNumero()
})

I know you're going to say that it's better to do a single method, but what I do not want to do, I need to get a value that will be generated in another function and use in another function.

    
asked by anonymous 10.10.2015 / 06:28

1 answer

2

What questions are perfectly valid and if you test it works .

To have more modular code would make sense, #

As renan said , pass the value already as argument like this:

function trazerNumero(){
    return 7;
}

function mostrarNumero(numero){
    alert(numero);
}

$(function(){
    var numero = trazerNumero();
    mostrarNumero(numero);
})
    
10.10.2015 / 07:26