What today I have learn about JavaScript

Md. Riduanul Haque
3 min readNov 3, 2020
  • Arrow Function: The arrow function is a new version of ES6. as we see ES5 function like

Example

const add = function add(num) {
return num + num
}

ES6 arrow function :

Example

const add = (num) => num + num; //return and curly bruces dropedconst add = num => num + num; // parenthesis also can removed//if dos'nt have any paremeter then you can write likeconst name () => {console.log('riduanul haque');};
  • Function Default Parameters: see two examples given below. hope you will understand about default parameters.

Examples

const add = function(num1, num2){
if (num2 == undefine){
num2 == 0
}
return num1 + num2;

}
const result = add(20 );
console.log(result) // 20;
// Now ES6 function default parametersconst add = num1, num2 = 0 => { num1 + num2}
const result = add(20);
console.log(result) // 20
  • Spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value. Syntex of spread operator — var variable name = [… variable name];

Example

var array1 = [1, 2, 3];
var array2 = [4, 5, 6];
var array3 = [...array1, ...array2];
console.log(array3) // [1, 2, 3, 4, 5, 6];
  • Block scope: In a simple way we can say whenever you see curly brackets, it is a block. In ES6, const and let keywords allow developers to declare variables in the block scope, which means those variables exist only within the corresponding block.
function student(){    if(true){
let first = 'male';
const second = 'female';

}
console.log(first);
console.log(secnd);

}

student();
  • Error handling try….catch

in javaScript, we can handle errors easily by using try….catch method. let's know how it works. at first, javaScript executes the try code {try….code} if there is no error then it will ignore the catch block. if there is an error it will ignore the rest try block. it will execute catch block. try….catch works on only run time error.

  • Coding Style: our code must be clean and well readable. that’s why we should follow some coding style. which I have given below.
  • javaScript commenting: The JavaScript commenting out means that you take a part of the code and surround it with JavaScript comment symbols. Comments are not executed by the browser, which means that they won’t be displayed. comments can be single-line: starting with // and multiline: /* ... */. bad practice is explaining about code. a good practice is a high-level overview of components of how they interact.

--

--