Some Topics About ES6

Block Bindings

var x;
let y;
const z = nextValue;

Var Declarations and Hoisting

var a = 5;
if (true){
var a = 5;
console.log(a); // 5
}
console.log(a); // 5
x=40;
console.log(x); //40
var x;
x=40;
console.log(x); //refferenceError:
let x;
x=40;
console.log(x); //SyntaxError:
const x;

Block Level Declarations

var x = 1;
let y = 1;
if (true) {
var x = 2;
let y = 2;
console.log(y);
}
console.log(x); // expected output: 2
console.log(y); // expected output: 1
console.log(y); // shows output: 2

Block Binding in Loops

for (var i=0; i < 10; i++) {
process(items[i]);
}

// i is still accessible here
console.log(i); // 10
for (let i=0; i < 10; i++) {
process(items[i]);
}

// i is not accessible here - throws an error
console.log(i);

Global Block Bindings

var global= "Hello!";
console.log(window.global); // "Hello!"

var newGlobal= "Hi!";
console.log(window.newGlobal); // "Hi!"
let global= "Hello!";
console.log(window.global); // "Hello!"
console.log(window.global=== global); // false
const newGlobal= "Hi!";
console.log(window.newGlobal); // "Hi!"
console.log("newGlobal" in window); // false

Functions with Default Parameter Values

function default(text){
console.log(text)
}
default("this is use input") //text= this is use input
function default(text = "this is default"){
console.log(text)
}
default() //text= this is default

Working with Unnamed Parameters

function allNumbers(x, y){
console.log(`x = ${x}, y = ${y}`
}
allNumbers(12, 13) // x = 12, y = 13
function allNumbers(x, y, ...z){
console.log(`x = ${x}, y = ${y}, z = ${z}`
}
allNumbers(12, 13, 45, 8, 6, 69) // x = 12, y = 13, z = 45, 8, 6, 69

Spread Operator

function totalNumber(x, y, z){
return x + y + z;
}
let numbers = [1, 2, 3];
console.log(totalNumber(numbers[1],numbers[2],numbers[3]);
//when use spread Operator it is so easy
console.log(...numbers);

Block Level Function

function english1(){
var a = 'story';
const b = 'Nobel';
let c = 'poem';
function english2(){
console.log(a);
console.log(b);
console.log(c);
}
english2();
}

english1();

//result:
//story
//Nobel
//poem

Arrow Functions

//Tradition Function
function func1(){
console.log("This normal function)
}
func1(); //This normal function;
//Arrow Function
const func2 = () => {
console.log("This arrow function)
}
func1(); //This arrow function;
const func3 = () => {
return "This function 3"
}
console.log(func3());
//another easy way to express arrow funciton
const func3 = () => "This function 3"
console.log(func3());

--

--

Hello, I am Mehadi Hasan, Frontend React web Developer. From my little knowledge about JavaScript I am trying to publish somethings.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mehadi Hasan

Hello, I am Mehadi Hasan, Frontend React web Developer. From my little knowledge about JavaScript I am trying to publish somethings.