ashri Posted July 3, 2010 Share Posted July 3, 2010 Is anyone there who mentions use of "return" in javascript in detail with some practical tutorials that why "return" is used in javascript. Link to comment Share on other sites More sharing options...
Ingolme Posted July 3, 2010 Share Posted July 3, 2010 Return is used to make a function return a value. function five() { return 5;}alert(five()); // Displays "5" Link to comment Share on other sites More sharing options...
ashri Posted July 3, 2010 Author Share Posted July 3, 2010 Return is used to make a function return a value.function five() { return 5;}alert(five()); // Displays "5" can you demonstrate me with more explanation i can't understand this yet. Link to comment Share on other sites More sharing options...
Synook Posted July 3, 2010 Share Posted July 3, 2010 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 More sharing options...
iwato Posted July 3, 2010 Share Posted July 3, 2010 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 More sharing options...
jeffman Posted July 3, 2010 Share Posted July 3, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.