No, it is not possible to pass arguments exclusively by reference to a function in JavaScript. This is because JavaScript passes primitive data types (e.g. numbers, strings, booleans) by value and objects (including arrays and functions) by reference.
When a primitive data type is passed to a function, a copy of its value is created and passed to the function. This means that any changes made to the parameter within the function are not applied to the original value.
When an object is passed to a function, a reference to the original object is passed. This means that any changes made to the parameter within the function will affect the original object.
Therefore, in JavaScript, it is not possible to pass primitive data types by reference without wrapping them in an object (e.g. passing an object containing a number instead of a number itself).
Asked: 2021-05-04 11:00:00 +0000
Seen: 11 times
Last updated: Jul 02 '22