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.

Define A Function

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.

Defining & Calling a Function

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

Add Parameter to Function

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.

Anonymous Function

JavaScript anonymous function is a function without a name.

show()

An Immediately-invoked Function Expression (IIFE)

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

JavaScript Arrow Fucntion

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

Pass Argument in JavaScript Arrow Fucntion

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 more than one Argument
let arrowFunction = (name, age) => {
return "My Name is "+ name+ "My Age is" + age;
}
arrowFunction("proNazmul", 25)

Arrow Fucntion Return is Not Needed:

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

arrowFunction("proNazmul")

Arrow Fucntion With Default Parameter Value

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.

// 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.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store