Skip to content

Instantly share code, notes, and snippets.

@kylejson
Last active August 29, 2015 14:01
Show Gist options
  • Save kylejson/f64eac8472a8b49a4acf to your computer and use it in GitHub Desktop.
Save kylejson/f64eac8472a8b49a4acf to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript">
function setHealth(obj) {
obj.hp = 100;
//obj = new Object();
//obj.hp = 50;
}
var Player1 = new Object();
setHealth(Player1);
alert("Avatar starts with HP: " + Player1.hp); //Player1's hp = 100;
</script>
</body>
</html>
@kylejson
Copy link
Author

This always alerts "Avatar starts with HP: 100". If we leave lines 12-13 commented seems a lot like pass by reference, however in the case that they are uncommented we are reassigning obj which creates a new object in memory but it doesn't persist outside of the function scope. Pass by value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment