Skip to content

Instantly share code, notes, and snippets.

@BuonOmo
Created October 17, 2016 00:28
Show Gist options
  • Save BuonOmo/46b36b90569d456ab2170f3afaa8e0fa to your computer and use it in GitHub Desktop.
Save BuonOmo/46b36b90569d456ab2170f3afaa8e0fa to your computer and use it in GitHub Desktop.
How to pass var by parameter or reference in javascript
/* =================================
Pass by parameter
================================= */
function par(e) {
e = "bar";
}
var a = "foo";
par(a);
console.log("a: "+a); // "foo"
/* =================================
Pass by reference
================================= */
function ref(e) {
e.ref = "bar"
}
var b = {}
b.ref = "foo";
ref(b);
console.log("b.ref: "+b.ref); // "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment