Spread vs Rest Operators in JavaScript
Lately i have been writing a lot of backend code and kept getting confuse when to use spread operator and when to use rest While searching the solution i realized many developers have same problem....

Source: DEV Community
Lately i have been writing a lot of backend code and kept getting confuse when to use spread operator and when to use rest While searching the solution i realized many developers have same problem. So in this blog i will break it down simply when to use each and common mistakes to avoid. Topics to Cover What rest operator does What spread operator does Differences between spread and rest When to Use the Rest and Spread Operator The Rest and Spread operator are two different operators but both uses three dots (...) so they can be confusing. Why are they using three dots in JavaScript if they are not same lets see individually Rest Operator Think of rest exactly like it name It means give me the rest of the values that are left const user = { id: 1, name: "Kunal", email: "[email protected]", role: "admin", password: "secret" }; // REST → extract password, collect remaining const { password, ...safeUser } = user; console.log(safeUser); The output of the above code // Password is extracted {