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




Partners: book of ra vlt casinos with zimpler casino dansk licens casino mga licens trustly betting sider uden rofus vavada casino funky time live history skrill guthaben auszahlen online casino mit skrill dansk casino uden rofus

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply