DEV Community

Md.  Raihan Hossain Jibon
Md. Raihan Hossain Jibon

Posted on

Functions

A Function is a way yo bundle code so that it can be reused. Functions allow us to run the same piece of code from multiple places in a program without having to copy paste the code repeatedly.

The Basic Anatomy of a function

Image description
The code between the curly brackets is called the function body.

Creating A Simple Function

Lets create a simple function. Enter the following code in the browser console.

Hello World!

const firstFunction = function () {
console.log("Hello World!);
}
Enter fullscreen mode Exit fullscreen mode

Passing Arguments into Function

firstFunction just prints the same line of text every time you call it, but you will probably want your function to be more flexible than that. Function argument allow us to pass value and change to function behavior.
Lets create function with argument

const secoundFunction = function (name) {
console.log("Hello" + name "!");
}
Enter fullscreen mode Exit fullscreen mode

We can send multiple argument also .

const secoundFunction = function (firstName, LastName) {
console.log("Hello" + firstName + LastName"!");
}
Enter fullscreen mode Exit fullscreen mode

More Information Updating Soon.

Top comments (0)