3 Ways to Create Javascript Functions





Hey guys in this post we will discuss the different ways of creating Javascript functions. There are 3 different ways to create javascript functions let’s discuss one by one

Three different ways


  • Function declaration
  • Function expression
  • Arrow function

Function declaration


Let’s look at the syntax

function (parameters) {
  //logic
}

Let’s look at the example

function printMessage(name, age, location) {
  console.log(`I am ${name} and i am ${age} year's old. I am living in a beautiful country ${location}`);
}

Function expression


Let’s look at the syntax

const  = function(parameters) {
  //logic
}

Let’s look at the example

const printMessage = function(name, age, location) {
  console.log(`I am ${name} and i am ${age} year's old. I am  living in a beautiful country ${location}`);
}

Arrow function


Let’s look at the syntax

const  = (parameters) => {
  //logic
}

Let’s look at the example

const printMessage = (name, age, location) => {
  console.log(`I am ${name} and i am ${age} year's old. I am  living in a beautiful country ${location}`);
}

Learn more about arrow function here




About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *