www.webdeveloper.com
Results 1 to 5 of 5

Thread: Question Javascript

  1. #1
    Join Date
    Jun 2013
    Posts
    23

    Question Javascript

    Hi,

    Im learning JavaSCript, but on one exercise i don't get it. This is the exercise:

    var gerrit = "Dit is een globale varriabel.";

    var globalFunction = function () {
    alert(gerrit)
    gerrit = "Dit is een wijziging.";
    };

    globalFunction ();

    alert(gerrit)



    Now is my question, what will do the globalFunciton (); on the one-last line of code? What is his function?

    THanks for helping!

    Reckimo

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    The lines with var define a global variable and a global function (this definition covers 4 lines).

    Then this globalFunction is called.

    This example show that a global variable like gerrit, can be changed in a function.

  3. #3
    Join Date
    Jun 2013
    Posts
    23
    But on line 6, (globalFunction (); ), what is his funciton? It's not an alert thing right. Does it execute something or just nothing?

  4. #4
    Join Date
    Jun 2013
    Posts
    23
    I mean, by saying only globalFunction ();, wil that execute the var globalFunction? Because there is not alert(globalFunction), so how can it be an pop-up? thanks.

  5. #5
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,270
    Yes the line globalFunction (); execute the globalFunction. This function use an alert to show the var gerrit.
    Try this variant to see all changes
    Code:
    // To define gerrit
    var gerrit = "Dit is een globale varriabel.";
    // To see gerrit
    alert('Before calling the function '+gerrit)
    
    // To define the function 
    var globalFunction = function () {
         // To show gerrit in the function before changing 
         	alert('Before changing : '+gerrit)
         gerrit = "Dit is een wijziging.";
         // To show gerrit in the function after changing 
         	alert('After changing : '+gerrit)
    
    };
    // To see the function
    globalFunction ('The function '+globalFunction);
    
    // To execute the function
    globalFunction ();
    
    // To see gerrit after  
    alert('Out, after executing the function '+gerrit)
    See for example this w3school.com page

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles