function

12 0 0
                                        

We have been using function in the example in the previous chapters. I will just play with functions in here.

=================

let globalVariable = "Global Variable: ";

function iWillTakeGlobal(talk){

     document.write('${globalVariable} ${talk}');

}

function iHaveMyOwnLocal(talk){

     let localVariable = "Local Variable: ";

     document.write('${localVariable} ${talk}');

}

function iAmAParameter(talk,){

     document.write('${parameterVariable} ${talk}');

}

function helloReturn(){

     return "Why are you not using me?";

}

function myFunctionalStory(){

     iWillTakeGlobal("Anyone can call me! ");

     iHaveMyOwnLocal("Oh! That is not my case. I am exclusive within this function wall. ");

     iAmAParameter("Your local? I am too. And I can have default values. ");

     document.write(helloReturn());

}

=================

HTML

document.write(myFunctionalStory())

Result:

Global Variable: Anyone can call me! Local Variable: Oh! That is not my case. I am exclusive within this function wall. Parameter Variable: Your local? I am too. And I can have default values. Why are you not using me?undefined


Note: The result should be a long line of text.

Javascript ProgrammingWhere stories live. Discover now