How to call a function in Javascript
Hey friends, Welcome to CodeWithNepal today in this blog you’ll learn how to call a function in Javascript. In the earlier blog, I shared Photomosaic Generator which I recommend you to watch.
Function in Javascript
A function is a block of code that performs a specific task. Parts are written in order to make code more reusable and easier to read. When a function is invoked or called, the code inside the part is executed.
Functions are an essential part of any programming language and JavaScript is no exception. In JavaScript, functions are objects. This means that they can be passed around as arguments to other functions, returned from functions, and assigned to variables.
Functions are declared with the function keyword followed by a name. The function name can be any valid JavaScript identifier.
Call a function in Javascript
example:
Assuming you have a function named myFunction:
To call a function in JavaScript, you need to use the function name followed by parentheses ().
myFunction();
Inside the parentheses, you can specify any arguments that the function needs to take. For example, if the function takes two arguments, you would write them like this:
myFunction(argument1, argument2);
You can also call a function without any arguments:
Get codewithnepal’s stories in your inbox
Join Medium for free to get updates from this writer.
myFunction();
example:
The call() method is a way to call a function with a given value and arguments provided individually.
This is especially useful for borrowing methods or for calling a superclass method from a subclass.
The call() function can be used on any function, including built-in functions. It can also be used on an object that is a function.
When called, the call() function will call the function with this value set to the first argument and the arguments provided as the second and subsequent arguments.
For example, let’s say we have a simple function that prints out this value and the arguments:
function printArgs(a, b, c) {
console.log(this, a, b, c);
}
If we call this function using the call() method we can set this value and the arguments individually.
You may like this blog:

![Best Smartphones to Buy in Every Price Segment in Nepal [Updated]](https://miro.medium.com/v2/resize:fit:1358/format:webp/0*Ks8FOqBh8DIbUkP1.jpg)







