---
title: "Discussion on \"Spread vs Rest Operators in JavaScript\" | Hashnode"
description: "Discussion on \"Spread vs Rest Operators in JavaScript\". Confused by ... in JavaScript? Learn how the spread operator expands values and the rest operator collects them, with real code examples."
url: "https://hashnode.com/posts/spread-and-rest-operators-in-javascript/6a9a516b17d2d5eb673a46c1"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Spread vs Rest Operators in JavaScript](https://sahilxdev.hashnode.dev/spread-and-rest-operators-in-javascript?utm_source=hashnode&utm_medium=feed)

Confused by ... in JavaScript? Learn how the spread operator expands values and the rest operator collects them, with real code examples.

Sep 4 · 8 min read · sahilxdev.hashnode.dev  
Updated Sep 6  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#webdev](https://hashnode.com/tag/webdev)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#programming-blogs](https://hashnode.com/tag/programming-blogs)
-   [#chaicode](https://hashnode.com/tag/chaicode)
-   [#chaicode-webdev-cohort-2026](https://hashnode.com/tag/chaicode-webdev-cohort-2026)
-   [#chaiaurcode](https://hashnode.com/tag/chaiaurcode)
-   [#chaicohort](https://hashnode.com/tag/chaicohort)

## Written by

[Sahil Gupta](https://hashnode.com/@sahilgupta2175)

@sahilgupta2175 · Bangalore, India

  
[View profile](https://hashnode.com/@sahilgupta2175)

Programmer Analyst Trainee at Cognizant

I'm a passionate software engineer and full-stack MERN developer who loves to turn ideas into scalable, user-centric applications. I have hands-on experience in building modern web solutions using React, Node.js, Express.js, MongoDB, following clean architecture and best development practices. My experience in the Cognizant Healthcare Product Consulting (HPC) program has given me hands-on exposure to SQL, PL/SQL, U.S. healthcare payer systems and TriZetto Facets, and has helped me to further develop my skills in working with enterprise software in domain-driven environments. I enjoy tackling complex technical problems, constantly learning, and building reliable applications that deliver business value.

## Responses 2

Markdown supported · ⌘↵ to post

[AI Tools Primer](https://hashnode.com/@aitoolsprimer)

[Sep 4](https://hashnode.com/posts/spread-and-rest-operators-in-javascript/6a9a516b17d2d5eb673a46c1/comment/6a9ad7becdeba61f2ff6fbeb)

Good breakdown. One thing worth adding, because it catches people who use spread as a "copy" operator: {...obj} copies own enumerable properties only. The prototype is not carried over, so {...new Date()} gives you {} and {...someClassInstance} loses every method, since methods live on the prototype and not on the instance. Getters are evaluated at spread time and become plain values, and anything non-enumerable simply disappears.

And on the spread-as-arguments side: Math.max(...arr) is elegant right up until arr is large. Every element becomes a real argument, so on big arrays you hit RangeError: Maximum call stack size exceeded, and the exact threshold is engine-dependent rather than specified. arr.reduce((a, b) => Math.max(a, b)) is the boring version that never blows up.

[Sahil Gupta](https://hashnode.com/@sahilgupta2175)

[Sep 6](https://hashnode.com/posts/spread-and-rest-operators-in-javascript/6a9a516b17d2d5eb673a46c1/comment/6a9ad7becdeba61f2ff6fbeb#reply-6a9cf7bec5fc1d5c066d656d)

This is a great addition, thanks for pointing it out! I kept the article focused on the "expand vs collect" mental model, but you're right that the enumerable-properties-only behavior (and the Math.max call-stack limit) are exactly the kind of thing that trips people up once they start using spread on real objects instead of plain literals. Updated the post to include both - appreciate you taking the time to write this out.
