w3resource logo


JavaScript Statements

JavaScript : Block statement

Secondary Nav

Description

Block statements are commonly used with control flow statements i.e. while, for, if etc. The block is delimited by a pair of curly brackets.

Syntax

{ 
statement_1 
statement_2
 .    .    . 
statement_n 
} 

Parameters

statement_1, statement_2, .... , statement_n

Where statements are grouped within the block statement.

Example :

 if x>10
  {
  y=12
  z=20
  }
  or while ( roll_no <= 40 )
  {
  roll_no++
  }

JavaScript does not support block scope. In the following example output of the variable a will be 1 because var a statement within or before condition have same scope whereas in Java or C language the output of the same code will be 101.

var a = 101
  {
  a = 1;
  }
  console.log(a) 
  //output 1


Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number