0

Is this possible? My purpose is to pass text variables and / or numbers with large sizes, therefore, if I pass a large value to the parameters in a function call, in order to make validations (validate messages, scores , etc. of great length) Is this value copied ?, that is, Would it be using twice the memory ?, Does JavaScript at this point do any String Interning or references for the primitive values internally?

For example, strings are immutable, therefore, wouldn't it be silly to pass a copy in the parameters, or if they are passed by reference?

In the case of numbers, likewise, if I only want to use (not manipulate) a number inside a function, is this number also passed as a copy or is it a reference internally?

So is this possible in JavaScript?

Hope you can help me understand c:

Grizzly
  • 371
  • 2
  • 13
  • Can you wrap the value in an object and pass the object? – Cat Sep 13 '21 at 15:40
  • [Is JavaScript a pass-by-reference or pass-by-value language?](https://stackoverflow.com/q/518000) – VLAZ Sep 13 '21 at 15:40
  • My purpose is not to mutate the primitive value (outside or inside of a function), but to reuse the same variable in memory, if a number and a string are immutable, internally, shouldn't they always point to the same address in memory? Why should I receive a copy of that value, if I am not going to mutate that value? as per the answer in this question, at least the strings if passed by "reference", https://stackoverflow.com/questions/1308624/pass-a-string-by-reference-in-javascript or I'm wrong? – Grizzly Sep 13 '21 at 16:00

0 Answers0