Calling functions with return statement

You can assign the result of a function to a variable. In this way the variable get the value returned from the function and you can use it later in the script.

function GetAllText() {
     var text1 = "I have a ";
     var text2 = "Honda PCX!";
     var AddText = text1 + text2;
     return AddText;

var TextAlert = GetAllText();

First we have a function and three local variables. The value of the third variable is basically the values of the first two variables combined. The function GetAllText() returns the value of the third variable. The result of the function GetAllText() is then assigned to the variable TextAlert which is then used to send an alert to the user with the result “I have a Honda PCX!”.

Leave a Reply