At a glance JavaScript (ES6)

Sabbir Ahmmed
3 min readMay 15, 2021

The journey of JavaScript is a long story. JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. From that time, JavaScript has changed its shape multiple times. Many version has been released by Ecma Internation. Now, I’m going to discuss here JavaScript (ES6) or ECMAScript 2016 edition. Here you can easily find out some important topics of modern JavaScript.

Variable

The most important part of any programming language is a variable concept. From the C/C++ programming language, we know that a variable has multiple data types and before the variable name it must be declared. For example, float PI = 3.1416. In JavaScript variable concept is so easy. We use generally in modern JavaScript const, let and var to declare any variable. JavaScript interpreter so much smart, it easily identifies string, integer, or float number. For example —

var PI = 3.1416;

var r = 10;

var sum = PI * (r*r) ;

console.log(sum);

This code is cool and right! This is JavaScript early version syntax. If we want to write that code ES6 so what will happen! Let’s see

const PI = 3.1416

let r = 10;

const sum = PI*(r*r);

console.log( sum );

Here, PI is a constant value. It is assumed that it is not changeable that’s why the PI variable is declared with const. On the other hand, r depends on the user, which means it is a changeable variable.

Nice to know that, const and let are block variables. If we declare those in scope, can’t use those outsides of scope. For example –

for(let i=0; i<10; i++){

const a = 1; // the variable inside of loop is called local variable

const b = 2;

const result = a + b;

}

console.log( result );

output : ReferenceError: result is not defined

Because of scope ‘{}’ restriction. Outside of scope, any variable is accessible in any place. It is called a global variable.

Condition

Condition is another hot topic of a programming language. We can express our logical thinking by condition. There are different kinds of logical expressions. They are –

If ( condition ){

// statement

}esle{

// statement

}

If ( condition ){

// statement

}else if( condition ){

// statement

}

Another,

switch( expression ){

case 1( condition ):

// statement

Break;

case 2( condition ):

// statement

Break;

default:

// statement

}

Loop

Loop is the repetition process of a particular task in JavaScript. In JavaScript loop has a different shape. For example –-

For-loop :

for( initial state ; condition ; increament/decreament ) {

// statement

}

If we want to print Bangladesh 10 times, we follow this expression –

for( let i = 0; i<5 ; i++ ){

console.log( ‘Bangladesh’ );

}

While — loop

While loop is a simple and easy process. It is the same as for-loop. For example —

If we want to print Bangladesh 20 times –

let n = 20 ;

while( n - -){

console.log( “Bangladesh” );

}

Do-while

Do while loop is a little bit different from for-loop and while loop. The statement of this loop must be executed at least once. For example –

let x = 30 ;

do{

console.log( “Bangladesh” );

}while( x — — );

Else, there are some other loops, we will discuss those in the array section.

Function

In every programming language, a function is an important topic. A function just like a container or shape for some specific task so that we can reduce our code size and optimize our code. A function can take one or more parameters. Inside a function we can declare one or more local variables and statements, even we can declare a function or return a function. A simple example of a function is –

const addSum = ( number1, number2 ) => {

return ( number1 + number2 );

}

const result = addSum(4,5);

console.log( result );

we can take multiple parameters in a function using the arguments keyword –

function addSum(){

let sum = 0;

for (let i = 0; i < arguments.length; i++) {

sum += arguments[i];

}

return sum ;

}

const result = addSum(4,5,1);

console.log( result );

--

--