Skip to content
This repository was archived by the owner on Apr 1, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions JS-Block.md
Original file line number Diff line number Diff line change
@@ -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;
}
```