Javascript Tutorial - 12 - Parameters in Functions

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
40,093
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Mar 13, 2008

visit www.thenewboston.com for all my tutorials!

please rate!

  • likes, 8 dislikes

Link to this comment:

Share to:

Top Comments

  • yes, but as the program becomes more complex, there will be more to it than simply adding two numbers. the point of the video is to show how to use parameters in a method that can be used over and over again. This method may contain several lines of code. If you had to use the method 10 times, you'd be saving a lot of time

  • Can someone explain why you don't have to declare the variable x? It makes more sense to me that inside the function you had to state:

    var x = a + b;

see all

All Comments (85)

Sign In or Sign Up now to post a comment!
  • awesomeness

  • @MegaTeddy000 In 'alert(add(32, 56))' , we tell JavaScript 'Open a popup box and for the value to be displayed, call the add() function with parameters 32 and 56'. So 'function add()' is read & the two numbers are added. Now assume that there is no 'return x' statement. So the addition of 32 & 56 will surely be performed; but the alert does not have a value to display. If you do write 'return x', the sum of 32 & 56 is calculated and returned i.e. alert( add(32,56) ) = alert(88) !

  • @MegaTeddy000

    A return statement pretty much returns a value back to, lets say... a variable, so you don't have to re write that variable many times. It's kinda hard to explain i had trouble with it for a long time. The best advice i can give u is to search "java return" or something like that until u get it.

  • i dont understand what return is for......can anyone explaine?

  • hmm this is like byval and byref in VB

  • @supersushi269 more extreme:

    function hi(x){

    for(i=0;i<x;i++){

    document.write("!!!1")

    }

    }

    document.write("OMG");

    hi(9001);

    lol

  • A real use of functions XD

    alert(add(1,add(1,add(1,add(1,­add(1,add(1,add(1,add(1,add(1,­add(1,add(1,add(1,0)))))))))))­));

    TRY IT!

  • @WillsEasyGuitar kk ty

  • @kindofgameplay if you dont tell the function what the return value is, it treats it like a boolean (true or false). giving the variable x, it sends the value of the two numbers added.

  • why

    return x; ??

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more