The Beginner's Guide to JavaScript Functions & Parameters.

Function plays the most important role in any programming language. Like other JavaScript, function helps you to make a block of code to perform a specific task. You can execute it as many times as you want.

The javascript function is defined by the function keyword, then the function name of function & pair of parentheses (). Function names can contain letters, numbers, underscores like variables.

function functionName() {
// Code to be executed
// Defining function
function sayHello() {
alert("Hello, Programmer You are welcome to this website!");

// Calling function
// 0utputs: Hello, Programmer You are welcome to this website!

You can pass values as argument while calling the function. Function receives values as parameter when you define a function. Function will manage values according to predefined instruction.

// Defining function
function addSum(num1, num2) {
var total = num1 + num2

// Calling function
displaySum(6, 20)
// 0utputs: 26
displaySum(-5, 17)
// 0utputs: 12

JavaScript anonymous function is a function without a name.

let show = function () {
console.log('This Is Anonymous function')

An Immediately-invoked Function Expression (IIFE) is an automatically executed functions.

(function() {
console.log('This Is Immediately-invoked Function')

JavaScript arrow function is more elegant and readable than javascript normal function.

let arrowFunction = () => {
return "This is JavaScript Arrow Function Example";

When passing a single argument in javascript arrow function no need to use parenthesis () & when passing two or more values then use parenthesis().

//Example using Single Argument
let arrowFunction = name => {
return "My Name is "+ name;
//Example using more than one Argument
let arrowFunction = (name, age) => {
return "My Name is "+ name+ "My Age is" + age;
arrowFunction("proNazmul", 25)

When You Write Single-line Arrow function Return is not required.

let arrowFunction = name => "My Name is "+ namearrowFunction("proNazmul")

You can set an arrow function with a default value. If you pass argument function will run using given arguments or not function will run using the default argument.

// Default Value will work in this function 
let defaultFunction=(name, age=25)=> "Name is"+ name +"Age is"+age; defaultFunction("proNazmul")
// Assigned Value will work in this function
let defaultFunction=(name, age=25)=> "Name is"+ name +"Age is"+age; defaultFunction("proNazmul", 23)

Hi, I'm Nazmul Huda. A full stack Web Application Developer. I love new challenges and working with new technologies.