Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Primitives Are Copied

Behind the Scenesmedium

Course · Section 8: How JavaScript Works Behind the Scenes · Lecture 103: Memory Management: Primitives vs. Objects

Implement `tryChange(n)` that passes `n` to a helper which reassigns its own parameter, then returns the original `n`. Primitives are copied, so the original is unchanged.

Sample tests

Input: tryChange(5)
Output: 5
Input: tryChange(0)
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Expecting the helper's reassignment to affect the caller's variable.
Visualize this concept: Primitives vs. References →
Approach & explanation (try first)

Primitives are passed by value, so reassigning the helper's parameter leaves the original untouched.

Loading...
⌘/Ctrl + Enter

Run your code to see results.