How to Call a Function in Javascript Let's see a basic example of how to call a function in Javascript as follows: To call a function we just need to write our function's name alongside the parentheses (this is a must) with the corresponding parameters, have in mind that any function's name is case sensitive, so we need to write the function's name in the correct case to call the right function. Now, if we run the code, we will get a message in our console. If more insight is needed to understand how a function works or how it is called, let's dive in on what a function is and its many forms with various examples. What is a Function and How to Call it in Javascript? The most common scenario in software development or projects is that they have a variety of different tasks, as well as they can contain a great variety of repetitive tasks, which throughout the code may appear on different occasions. Since we know that this is something that will surely happen in our development process, it is a good idea to include these repetitive tasks in a module or code block and reuse them when necessary, these modules or code blocks are called functions . So, how to call a function in Javascript? Before answering this question, we need to understand how to write a function. Let's see the general syntax of a function in the following example: In order to declare a function, first, we need to write the keyword , since this is a Javascript keyword, it must be always written in lowercase (otherwise we will get an error). Next to the keyword, we will write the function's name , in this case, is , next to the name we have the parentheses , where the parameters to be used in the function will be contained (in this case the parameters are and which will be the numbers to be summed). Last but not least, we have the curly braces , where the body or statements of the function will be written. If we run the code as it is, nothing will happen since we just declared the function. If we want to execute the function we need to call it. A simple way to call the previous function is the following: As we already mentioned previously, to call a function we need to right the function's name, in this case, is alongside the parentheses with the corresponding and parameters like this . And what if we are a bit lazy to think of a name for our function? Good news, we can declare functions without giving them a name, these functions are called anonymous How to Call a Function in Javascript? (Anonymously) In order to declare an anonymous function, we must write the keyword followed by the parentheses and the curly braces . Let's say we want to show in the console a "Hello World" message as follows: As you already know, if we run the code as it is, nothing will happen. To call this anonymous function, first, we need to store the same in a variable like this: And then call it by the variable's name alongside the parentheses, similar to the way that we called a normal function: It is highly recommended to store anonymous functions in a variable declared by the keyword , this is to avoid changing its value later on in our program. There is another type of function in Javascript called Class that is very similar to a normal function but differs in some points from it. Let's see what is a Class in Javascript and how we call this type of function. How to Call a Function in Javascript? (Class Functions) A class is like a template for creating objects, objects created from the class will have the same characteristics and are known as attributes and methods. To have a clearer idea, imagine that the class is a cookie mold, the mold represents the class from which you can build or make objects, which in this example would be cookies. Although all the cookies are the same in terms of their shape, each one has different decorations, these decorations would be the properties or attributes of each object. Each class internally has a constructor to create the attributes of each object and as an additional feature, a class has methods, and methods are nothing more than functions that an object can have. Let's see the following example: First, we have a function called that receives and as parameters. Then we simply add the and that comes as a parameter to the instance that is created through that constructor function writing before each parameter. Now to get the same result but with a different structure, we have a class, using the keyword followed by the name of our object (always starting with a capital letter). Unlike the function, here we have to explicitly declare the and its parameters. As stated above, a class can have methods, that are simply functions. Let's add two methods to the class , one for setting a new country and the other to get the language of our object (in this case the Human): Once we have our class created, we can proceed to create new objects from it. Let's show in our console 2 humans using the class as follows: As you can see, we need to c