Sitemap
Annoydey

Annoydey

Web Developer and Programmer

10 Importing things about Javascript & ES6

4 min readNov 5, 2020

1. Function Default Parameter :- It is similar to function but programmer can set default value for backup. For example:-

Normal Function :-

function add(a,b){
return a + b;
}
Sum = add(15, 1) // result = 16

Default Parameter :-

function add(a,b=15){
return a + b;
}
Sum = add(15) // result = 30
function add(a,b=15){ // b=15 is not considered because user already pass the value
return a + b;
}
Sum = add(15,2) // here, result will be 17

2. Template String :- Template string is a string where you can add a value in a dynamic way. For example:-

const a = “Hello”;
const b = “World”;
const x = `${a} ${b}`; // result Hello World
const z = `${a} ${5+5}`; // result will be Hello 10

Remember always use ` ` template sign when you are using template string.

3. Arrow Function :- Function which declare in variable (function expression) and this function behave like normal function. For example:-

const z = function square(n){
return n * n;
}

In ES6 it can be written as following way :-

const z = n => n*n; // arrow function
// another example
const y = (a,b) => a * b;
y(5,6) // result is 30

4. Spread Operator :- It’s like concatenating 2 or more array in an single array in different way and we need to add three dots (…) before array name. For example :-

const x = [1,2,3];
const y = [4,6,7];
const array1 = x.concat(y).concat([5]);// Here,we adding 5 between two array in normal way
const array2 = […x,5,…y]; // By using spread operator

5. Undefined and Null :- If the variable declared but not initialized it is known as Undefined and When we assigned a variable but value is no given it is known as Null.

Get Annoydey’s stories in your inbox

Join Medium for free to get updates from this writer.

Undefined Example :-

function add(a , b){
console.log(a,b)
}
const sum = add(2);
console.log(result); // Here result is undefined

6. Double Equal (==) and Triple Equal (===) :- If one variable have number and another variable have string of that first variable of number and we are comparing with this Double equal (==) then after checking condition it will give us true value. On the other hand if we put Triple equal(===) instead of Double equal(==) then it will give us false because double equal didn’t check the type that’s why it give true value but triple equal check type also that’s why it give false value. For example :-

const a = 2;
const b = “2”;
if(a == b){
console.log(“true”)
}
else{
console.log(“false”)
}
// Here result is true because we use Double equal
const x = 3;
const y = “3”;
if(x === y){
console.log(“true”)
}
else{
console.log(“false”)
}
// Here result is false because we use Triple equal

7. Map, Filter , Find on Array :-

a) Map :- After apply .map to an array we do the operation and after that we can get array. For example :-

const num = [1,2,3,4,5,6];
const result = num.map(function(element){
return element * element;
})
console.log(result);

b) Filter :- By giving a specific condition we can filter an element from an array by using .filter. Filter can be use as by the following way. For example :-

const num = [1,2,3,4,5,6];
const bigger = num.filter( x => x > 3);
console.log(result); // output is 4 , 5 ,6

c) Find :- The special version of filter is find. If we want to know whether the value was inside an array or not that time we can use the .filter.

const num = [1,2,3,4,5,6];
const bigger = num.find( x => x > 3);
console.log(result); // Here output is only 4

8. Closure :- If we create function and inside function we return another function and stored in variable after that when we call that function several time it will increases value but when we again put that function in another variable and call that same function again it will start from first so we can say that it’s creating close scope and that’s why we called this as a closure. For example :-

function x(){
let count =0;
return function(){
count++;
return count;
}
}
const z = x();
console.log(z()); // here output is 1
console.log(z()); // here output is 2
console.log(z()); // here output is 3
console.log(z()); // here output is 4
const z1 = x();
console.log(z1()); // here output is 1
console.log(z1()); // here output is 2
console.log(z()); // here output is 5

9. Array slice, splice :-

a) Slice :- It is used for slicing an array.

const num = [1,2,3,4,5,6];
const part = num.slice(2,5); // start index 2 and end index 5
console.log(part); // Here output is [3,4,5]

b) Splice :- It is used for slicing array permanently and later on we can’t find those elements from an array. Another thing is that , in splice we have to use index and delete count but in slice we used only starting index and end index.

const num = [1,2,3,4,5,6];
const removed = num.splice(2,3); // start index 2 and 3 is using for delete count
console.log(removed); // Here output is [1,2,6]

10. Accessibility :- It’s a creation of a website that can be used by anyone. WebAIM WAVE is accessibility browser extension.

--

--

Annoydey
Annoydey

Written by Annoydey

0 followers

Web Developer and Programmer