function keyword

JavaScript Functions 4 Ways

What Is the function of JavaScript?
Functions are one of the fundamental building blocks in JavaScript. A function is a JavaScript procedure - a set of statements that performs a task.

To use functions, you must define or declared in the scope from which you wish to call it.
Functions are declared or defined with the function keyword.  You can write a function in four ways and it looks like..

JavaScript Functions 4 Ways -
1.      Function Declaration
2.      Function Expression
3.      Arrow Function Expression
4.      Concise Arrow Function expression

Example -
//Way-1
//Function Declaration
function fn1_Square(a, b){
    let square = a*b;
    return square;
}

//Way-2
//Function Expression
const fn2_Square = function(a,b){
     let square = a*b;   
    return square;
}

//Way-3
//Arrow Function Expression
const fn3_square = (a, b) => {
    let square = a*b;   
    return square;
}

//Way-4
//Concise Arrow Function Expression
const fn4_square = (a,b) => a*b;


I hope you enjoyed this post. So please write your thoughts in the below comment box. Thank you so much for reading this post.
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^