HOW TO USE FUNCTION IN JAVASCRIPT

Johnson Orji
2 min readMay 10, 2021

Firstly we will start by understanding what javascript function is all about!!

What is javascript function?

JavaScript functions are custom blocks of code that can be reused. Functions allow code to be more modular and are essential to object-oriented programming. Functions can be defined through declarations or expressions.

Functions are blocks of code that perform an action and may return a value. Functions can be customized based on your needs and can be used to make your code more efficient and modular.

In this tutorial, we’ll explore the basics of functions: how to define a function, how to call a function, and when they may be useful.

How to Use the JavaScript Define Function

There are two ways to define a function in JavaScript: through declarations and expressions. Let’s start with the declaration method of defining a function.JavaScript Function Declarations

Function Declarations define a named function. In order to define this type of function, you should start your code with the function keyword, followed by the name of the function.Function names follow the same rules as variables — they can use leers, underscores, numbers, and are often written using camel case. Then, after the variable name, you’ll include a set of parentheses, where optional parameters can be held. We’ll get to those later in the article.

Then, like a for or an if statement, the code of the function will be in curly braces.

JavaScript Function Expression

Another way of declaring a function is to create a function expression. We can do so by assigning a function to a variable.

Function Parameters

So, we need to make use of parameters. If we add a name parameter to our JS function, then we can print any name to the console through our function.

Calling or invoking of function.

CONCLUSION….

Overall, a function is a block of code that can perform an action and return a variable. Functions are useful if you have multiple lines of code that you may need to execute many times throughout a program.

Instead of writing those multiple lines of code every time you need to use them, you can add them to a function and call the function when you need to run the code, and pass the values you need to use into your function.

I AM SURE YOU GOT VALUE!!!!!

--

--

Johnson Orji

I am johnson orji , i develop website and i am a content creator!!