From 5e29eb278425f9b86699866f3b37dc090f3f8a06 Mon Sep 17 00:00:00 2001 From: Daksh Shah Date: Wed, 29 Jun 2016 21:25:53 +0300 Subject: [PATCH 1/2] Add JS Article Return --- JS-Return.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 JS-Return.md diff --git a/JS-Return.md b/JS-Return.md new file mode 100644 index 000000000..90e06da16 --- /dev/null +++ b/JS-Return.md @@ -0,0 +1,31 @@ +# JavaScript Return + +## Introduction + +When a **return** statement is called in a function, the execution of this function is stopped. If specified, a given value is returned to the function caller. If the expression is omitted, `undefined` is returned instead. + +```javascript +return [[expression]]; +``` + +[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return) | [MSDN link](https://msdn.microsoft.com/en-us/library/22a685h9.aspx) + +## Examples + +The following function returns the square of its argument, **x**, where **x** is a number. + +```javascript +function square(x) { + return x * x; +} +``` + +The following function returns the product of its arguments, **arg1** and **arg2**. + +```javascript +function myfunction(arg1, arg2){ + var r; + r = arg1 * arg2; + return(r); +} +``` From 2dc4f6b651a327a6dd6d8f340640380f123c9c6e Mon Sep 17 00:00:00 2001 From: Daksh Shah Date: Wed, 29 Jun 2016 22:01:49 +0300 Subject: [PATCH 2/2] Add repl links to run code --- JS-Return.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/JS-Return.md b/JS-Return.md index 90e06da16..f6e11a3de 100644 --- a/JS-Return.md +++ b/JS-Return.md @@ -20,6 +20,8 @@ function square(x) { } ``` +:rocket: [Run Code](https://repl.it/C7VT/0) + The following function returns the product of its arguments, **arg1** and **arg2**. ```javascript @@ -29,3 +31,5 @@ function myfunction(arg1, arg2){ return(r); } ``` + +:rocket: [Run Code](https://repl.it/C7VU/0)