Created
October 17, 2016 00:28
-
-
Save BuonOmo/46b36b90569d456ab2170f3afaa8e0fa to your computer and use it in GitHub Desktop.
How to pass var by parameter or reference in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ================================= | |
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