Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Docs: Explain shallow copy behavior for slice method #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kartikeymishra2202 wants to merge 1 commit into sudheerj:master
base: master
Choose a base branch
Loading
from kartikeymishra2202:docs/clarify-slice-copy

Conversation

@kartikeymishra2202
Copy link

@kartikeymishra2202 kartikeymishra2202 commented Oct 9, 2025

##The Problem:Question-5.
The current documentation for Array.prototype.slice() is correct but incomplete. It omits the crucial detail that it performs a shallow copy. This can be misleading and lead to hard-to-debug issues when developers work with arrays of objects, as the original array's nested objects can be unintentionally mutated.

The Solution

This PR addresses this gap by making the behavior explicit and providing a clear example. The changes include:

Adding a new subsection, "A Note on Shallow Copying", to the slice() documentation.

Clearly explaining that slice() copies references to nested objects, not the objects themselves.

Providing a concise code example that demonstrates this effect.

Updating the slice vs. splice comparison table to reflect this important detail for quick reference.

The Benefit

This clarification will help developers avoid common pitfalls and prevent unintentional mutations. It makes the documentation more robust and helpful, especially for those who are new to this concept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@Ramkrishna-KGL732 Ramkrishna-KGL732 Ramkrishna-KGL732 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /