Strings in Javascript are already passed "by reference" -- calling a procedure with a string does not involve copying the string's contents. There are two issues at hand:

  • Strings are immutable. In contrast to C++ strings, once a JavaScript string has been created it cannot be modified.
  • In JavaScript, variables are not statically assigned slots like in C++. In your code, metric is a label which applies to two entirely separate string variables.

Here's one way to achieve what you want, using closures to implement dynamic scoping of metric:

function Report(a, b) {
    this.ShowMe = function() { alert(a() + " of " + b); }
}

var metric = "count";
var metric_fnc = function() { return metric; }
var a = new Report(metric_fnc, "a"); 
var b = new Report(metric_fnc, "b"); 
a.ShowMe();  // outputs:  "count of a";
metric = "avg";
b.ShowMe();  // outputs:  "avg of b";
Answer from John Millikin on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String
String - JavaScript | MDN
Returns the index within this string of the last occurrence of searchValue, or -1 if not found. ... Returns a number indicating whether the reference string compareString comes before, after, or is equivalent to the given string in sort order.
🌐
W3Schools
w3schools.com › jsref › jsref_obj_string.asp
JavaScript String Reference
HTML wrapper methods return a string wrapped inside an HTML tag. These are not standard methods, and may not work as expected. The HTML wrapper methods are deprecated in JavaScript.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-reference
JavaScript String Reference - GeeksforGeeks
Localization: Adapting applications for different languages and regions using string methods like toLocaleString(). JavaScript strings can be compared with other data types to understand their unique properties:
Published   July 23, 2025
🌐
W3Schools
w3schools.com › js › js_string_methods.asp
JavaScript String Methods
JS Examples JS HTML DOM JS HTML Input JS HTML Objects JS HTML Events JS Browser JS Editor JS Exercises JS Quiz JS Website JS Syllabus JS Study Plan JS Interview Prep JS Bootcamp JS Certificate JS Reference ... Javascript strings are primitive and immutable: All string methods produce a new string without altering the original string.
🌐
Tutorial Republic
tutorialrepublic.com › javascript-reference › javascript-string-object.php
JavaScript String Properties and Methods - Tutorial Republic
This chapter contains a brief overview of the properties and method of the global String object. The JavaScript String object is a global object that is used to store strings.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › Strings
Handling text — strings in JavaScript - Learn web development | MDN
Since we use quotes to indicate the start and end of strings, how can we include actual quotes in strings? We know that this won't work: ... const goodQuotes1 = 'She said "I think so!"'; const goodQuotes2 = `She said "I'm not going in there!"`; Another option is to escape the problem quotation mark. Escaping characters means that we do something to them to make sure they are recognized as text, not part of the code. In JavaScript, we do this by putting a backslash just before the character.
🌐
The Valley of Code
thevalleyofcode.com › javascript-string
JavaScript Reference: String
JavaScript Reference: String · All about the JavaScript String properties and methods · The String object has one static method, String.fromCharCode(), which is used to create a string representation from a sequence of Unicode characters.
🌐
Medium
eytanmanor.medium.com › how-to-hold-strings-by-reference-in-javascript-9ef0de2ff08f
How to hold strings by reference in JavaScript | by Eytan Manor | Medium
July 18, 2020 - How to hold strings by reference in JavaScript JavaScript strings are held by value, and behave exactly like any other primitive. This means that each time we slice a string, we actually occupy extra …
Find elsewhere
🌐
Butterfly
getbutterfly.com › home › javascript arrays & objects › methods, events and scopes › the complete javascript strings reference
The Complete JavaScript Strings Reference – getButterfly
August 9, 2022 - JavaScript strings are deceptively complex constructs. There are actually two different types of strings – string Literals and string Objects – and they both behave somewhat differently, even while trying to masquerade as the other. Strings, in addition to having some pretty funky methods of dubious usefulness, have a great many oversights and shortcomings which can be smoothed over with a few prototypes. This reference will cover the difference between String Literals and String Objects, Strings’ properties and methods, some common and practical uses of Strings (particularly in regard to JSON and AJAX), and offer a few, useful prototypes to extend the String class.
🌐
Impressive Webs
impressivewebs.com › home › javascript string methods reference
JavaScript String Methods Reference - Impressive Webs
August 8, 2022 - A compilation of JavaScript string methods for easy lookup with code examples and details for each method mentioned.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › raw
String.raw() - JavaScript | MDN
// A String.raw template allows a fairly readable regular expression matching a URL: const reRawTemplate = new RegExp( String.raw`https://developer\.mozilla\.org/en-US/docs/Web/JavaScript/Reference/`, ); // The same thing with a regexp literal looks like this, with \/ for // each forward slash: const reRegexpLiteral = /https:\/\/developer\.mozilla\.org\/en-US\/docs\/Web\/JavaScript\/Reference\//; // And the same thing written with the RegExp constructor and a // traditional string literal, with \\. for each period: const reStringLiteral = new RegExp( "https://developer\\.mozilla\\.org/en-US/do
🌐
TutorialsPoint
tutorialspoint.com › home › javascript › javascript strings object
JavaScript Strings Object
September 1, 2008 - The string is a sequence of characters containing 0 or more characters. For example, 'Hello' is a string. JavaScript strings can be created as objects using the String() constructor or as primitives using string literals.
🌐
W3Schools
w3schools.com › js › js_strings.asp
JavaScript Strings
JS Examples JS HTML DOM JS HTML ... JS Bootcamp JS Certificate JS Reference ... A JavaScript string is zero or more characters written inside quotes....
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › at
String.prototype.at() - JavaScript | MDN
The at() method of String values takes an integer value and returns a new String consisting of the single UTF-16 code unit located at the specified offset. This method allows for positive and negative integers. Negative integers count back from the last string character.
🌐
W3Schools
w3schools.com › jsref › jsref_string.asp
JavaScript String() Method
String() is an ECMAScript1 (JavaScript 1997) feature.
🌐
Programiz
programiz.com › javascript › library › string
JavaScript String Methods | Programiz
JavaScript automatically converts primitive strings to String objects so that it's possible to use String methods and access properties even for primitive strings. In this reference page, you will find all String methods and properties available in JavaScript.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › String
String() constructor - JavaScript | MDN
The String() constructor creates String objects. When called as a function, it returns primitive values of type String.