https://www.w3schools.com/js/tryit.asp?filename=tryjs_function_return <!DOCTYPE html> <html> <body> <h2>JavaScript Functions</h2> <p>This example calls a function which performs a calculation and returns the result:</p> <p id="demo"></p> <script> var x = myFunction(4, 3); document.getElementById("demo").innerHTML = x; function myFunction(a, b) { return a * b; } </script> </body> </html> ' oppure L'operatore () richiama la funzione ' Utilizzando l'esempio precedente, toCelsiusfa riferimento all'oggetto funzione e toCelsius()fa riferimento al risultato della funzione. ' L'accesso a una funzione senza () restituira' la definizione della funzione anziche' il risultato della funzione: https://www.w3schools.com/js/tryit.asp?filename=tryjs_farenheit_to_celsius_2 <!DOCTYPE html> <html> <body> <h2>JavaScript Functions</h2> <p>Accessing a function without () will return the function definition instead of the function result:</p> <p id="demo"></p> <script> function toCelsius(f) { return (5/9) * (f-32); } document.getElementById("demo").innerHTML = toCelsius; </script> </body> </html> |