Explained with practical examples .The Difference Between The Spread Operator and The Rest Operator
Both the spread operator and the rest operator look exactly the same in JavaScript. This can be confusing if you don’t know the difference between these two operators.
In this article, we will learn about the differences between these operators with some practical examples. Let’s get right into it.
Rest parameters help us to pass an infinite number of function arguments.
Here is an example:
function sum(a,b,...remaining){
console.log(a);
console.log(b);
console.log(remaining);
}
sum(1,2,3,4,5,6);
// a => 1
// b => 2
// ...remaining => [3,4,5,6]
In the above example, the arguments a
and b
refer to 1 and 2 while the rest parameter …remaining
refers to everything we passed after 1 and 2. The rest parameter in this example is represented as an array [3,4,5,6]
when calling the function.
So we are using the rest operator to extract all the remaining array values and put them in an array.
With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...
You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...
Today I’m going to show you 13 well-know and popular tools to write better and cleaner JavaScript code. These are tools that I’m using right now on my JavaScript developer journey. So if you want to improve the quality of your projects, this list is for you.
We are the best offshore web development company in India providing web applications on Blockchain, AI & Chatbots. 15+ Yrs Exp., Save upto 60% on development.
Hire Dedicated JavaScript Developers from a top javascript development agency for your business solutions. We provide JS web developers for hire at a fixed or hourly rate.