From 46aad68187f30cdb793672e8dc7dc4cd76d569ef Mon Sep 17 00:00:00 2001 From: Daksh Shah Date: Mon, 27 Jun 2016 21:13:57 +0300 Subject: [PATCH] Add JS Block Article --- JS-Block.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 JS-Block.md diff --git a/JS-Block.md b/JS-Block.md new file mode 100644 index 0000000000..6dcb534e5d --- /dev/null +++ b/JS-Block.md @@ -0,0 +1,36 @@ +# JavaScript Block + +## Introduction + +In computer programming, a **block** or code **block** is a section of code which is grouped together. Blocks consist of one or more declarations and statements. A programming language that permits the creation of blocks, including blocks nested within other blocks, is called a block-structured programming language. JavaScript is one such programming language. + +A **block** statement in JavaScript is used to group zero or more statements. The block is delimited by a pair of curly brackets. + +```javascript +{ + statement_1; + statement_2; + ... + statement_n; +} +``` + +[MDN link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block) + +## Examples + +The **block** statement is commonly used with control flow statements (e.g. `if...else`, `for`, `while`) and functions. + +```javascript +while (x < 10) { + x++; +} +``` + +```javascript +function addnums(num1, num2) { + var sum = 0; + sum = num1 + num2; + return sum; +} +```