Last active
August 29, 2015 14:16
-
-
Save awilson28/60ab45fc882906371867 to your computer and use it in GitHub Desktop.
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
//this function is a 'side-effects' function: it doesn't return anything, it just changes the values passed in | |
function changeStuff(num, obj1, obj2){ | |
//remember that parameters are implicit variable declarations; these three parameters | |
//are variables local to this function | |
num = num * 10; | |
obj1.item = "changed"; | |
obj2 = {item: "changed"}; | |
} | |
var num = 10; | |
var obj1 = {item: "unchanged"}; | |
var obj2 = {item: "unchanged"}; | |
changeStuff(num, obj1, obj2); | |
console.log(num); // 10 | |
console.log(obj1.item); // 'changed' | |
console.log(obj2.item); // 'unchanged' | |
//EXAMPLE 2: | |
function f(a,b,c) { | |
a = 3; | |
b.push("foo"); | |
c.first = false; | |
} | |
var x = 4; | |
var y = ["eeny", "miny", "mo"]; | |
var z = {first: true}; | |
f(x,y,z); | |
console.log(x) // 4 | |
console.log(y) // ["eeny", "miny", "mo", "foo"] | |
console.log(z) // {first: false} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment