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")
}
Additionally, you could mention there are () which means that functions can also take some arguments.
function Sum(a, b){
console.log(a+b)
}
After creating functions we must call them in our code whenever we want:
function Sum(a, b){
console.log(a+b)
}
Sum(2,3)
Top comments (0)