Pass a variable into jquery from javascript - document.ready

Hello guys; I am going crazy looking for a way to overcome this block; I create a variable in a javascript function and I would like to pass it inside a jquery function; this jquery function starts at the click of a button and is in turn enclosed within a document.ready function

Can someone help me?

function tendina() {

var numeroFilmimportati = "Hello";

return numeroFilmimportati;

}

$(document).ready(function showOption() {

    $("#salvaInput").click(function pulsanteSalva(numeroFilmimportati) {

        alert(numeroFilmimportati);

});

});
        

Your variable is local in the tendina() function. So you cannot access it from outside. But your function is returning the content of the variable, so you can just log the return of the function


function tendina() {

var numeroFilmimportati = "Hello";

return numeroFilmimportati;

}

$(document).ready(function showOption() {

    $("#salvaInput").click(function pulsanteSalva(numeroFilmimportati) {

        alert(tendina());

});

});