DEV Community

8bit Programmer
8bit Programmer

Posted on

Day 2 Function Basic in js

Basic of Function in js

function hello()
{
  console.log("hello")
}

hello()
Enter fullscreen mode Exit fullscreen mode

With parameters

function hello(name,message)
{
  console.log(`hello ${name} ${message}`)
}

hello("Dev","Welcome")
Enter fullscreen mode Exit fullscreen mode

With return
If we want the function to return the procesed value return is used
A function can contain only one return

function hello(name,message)
{
  return `hello ${name} ${message}`
}

console.log(hello("Dev","Welcome"))
Enter fullscreen mode Exit fullscreen mode

With Arrow Function (ES6)

const hello = () => {
return  `hello ${name} ${message}`
}

console.log(hello("Dev","Welcome"))
Enter fullscreen mode Exit fullscreen mode

Top comments (0)