Jump to content

why "rerurn" is used in javascript


ashri

Recommended Posts

A function is a structure that takes zero or more values as arguments, and returns a single value. For example, Ingolme's function five() takes no values, and returns a number, being 5. I can write another function:

function add(a, b) {	return a + b;}alert(add(3, 2)); // Displays "5"

Here, the function takes two arguments, and returns the sum of them.The return keyword simply specifies what the function should return.

Link to comment
Share on other sites

can you demonstrate me with more explanation i can't understand this yet.
If you would like to understand how to create a function and use the alert() function then click on the highlighted text in this sentence.Roddy
Link to comment
Share on other sites

return is also used to terminate a function. It is often used in combination with if statements, so that a function can terminate if one condition exists, but continue to execute if another condition exists. An example

function square(num){   var squared;   if (typeof num != "number")   {	  return; // function terminates here   }   squared = Math.pow(num, 2);   return squared;}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...