Javascript Functions
In this blog, we will explore the basics of function in Javascript

Search for a command to run...
In this blog, we will explore the basics of function in Javascript

No comments yet. Be the first to comment.
This Javascript Blog series is for beginners who wish to start their journey in Javascript. We will cover Javascript topics from basic to advanced levels and some projects to practice the concepts.
In this blog, we will explore the string and its methods & properties in Javascript
Scalable Wireless Distributed Consensus for Autonomous Vehicles at Unsignalized Intersections

The Ultimate VLSI Roadmap is designed to help students and professionals gain clarity in choosing a role for their future careers.

A convolutional neural network (CNN) is a type of artificial neural network used primarily for image recognition and processing, due to its ability to

Natural language processing (NLP) is a branch of artificial intelligence that helps computers understand, interpret, and manipulate human language.

Introduction to Python

As we all know Javascript Statements are executed in the order that we coded and there is a scenario when we need to execute a particular block of code whenever it is needed. In such a case, we will give the block of code inside curly braces which are known as Function, that is used to execute the code whenever it is needed(i.e., by calling the function).
Let us take an example,
function add() {
let X= a + b;
console.log(X);
} //Function Definition
add(); //Function Call
In the above example,
function - It is a keyword to declare the function.
Function identifier - add() is a function name to identify the function uniquely and the rules to declare the function identifier is the same as the declaration of the variable name.
The code which is needed to be executed at a certain time is given inside a block and it is known as a function definition(i.e., defining the function).
function add(parameter_1, parameter_2){
//Block of code
} //Function Definition
add(Argument_1, Argument_2); //Function call
Note:-
Arguments and parameters inside the function are local variables (i.e., they can be accessed only within the function and not outside the function.Let us understand with an example to add and print two numbers.
function add( A,B ){
let X = A +B;
console.log(X); //11
} // Function Definition
add( 5,6 ); //Function Call
In the above example, the Task to perform is to add and print two numbers. Here function name is add.
Steps to how the function is executed:-
Step - 1: To execute the function(i.e., function definition), it should be invoked by calling its function name.
Step - 2: Arguments(i.e., values) will be received by the function parameters and then they will be passed inside the function definition block and perform the task.
Let us see an example,
function add(a,b){
return a + b;
}
let x = add(5,4);
console.log(x); //9
In the above example, we are performing the addition of two numbers, as we have seen before the function will be invoked and started to execute. Once the function execution reaches a return statement. It will stop the execution and return back its value to the function call statement and then it will execute the statement next to the function call statement. Here we are storing the return value in the variable x and then it is printed in the browser console.
In the next blog, we will explore Callback and arrow functions in Javascript.