Skip to main content

Posts

Showing posts from April, 2022

ES 6: Different between REST and SPREAD Operators

Java-Script Rest and Spread Operators:  In JavaScript, we are using three dots ( ... ) for both REST and SPREAD Operators. But these two operators are not the same they both have a different purpose. REST Operator - Purpose of this operator is to collect all remaining elements into the array. - For Example:           - let take one array in below example      - O/P :       Necklace [ 'Earring', 'Payal', 'Brooch', 'Bangles']   - In the Above example three-dot contain the rest of the product time in the restProdcut variable that calls Destructuring that breaks our code into small pieces.   - so in the above example, mainProduct variable contains my Main product and restProduct varibale contains my rest products.   - The rest operator always gives rest data into array format only.   - while creating function we can also use rest operator like below SPREAD Operator:  - It's work opposite to rest operators, like in rest operator we are collecting item