DEV Community

vrezhhakobyan
vrezhhakobyan

Posted on

JavaScript Functions

Functions are little code pieces used to do some tasks and make code shorter and more understandable. For example, it is unnecessary to write the same line of code many times. Instead, you can create a function and tell him how often some task is done.
In JavaScript, to declare a function we use the command

function Name(){

}

As you can see, the structure is very simple. You can use any name for your function and in {} write your function.

function SayHello(){

 console.log("Hello")
Enter fullscreen mode Exit fullscreen mode

}

Additionally, you could mention there are () which means that functions can also take some arguments.

function Sum(a, b){

 console.log(a+b)
Enter fullscreen mode Exit fullscreen mode

}

After creating functions we must call them in our code whenever we want:

function Sum(a, b){

 console.log(a+b)
Enter fullscreen mode Exit fullscreen mode

}

Sum(2,3)

Top comments (0)