Last active
December 30, 2015 20:39
-
-
Save nola/7882227 to your computer and use it in GitHub Desktop.
Passing objects to functions.If you pass an object (i.e. a non-primitive value, such as Array or a user-defined object) as a parameter, and the function changes the object's properties, that change is visible outside the function, as shown in the following example:
This file contains hidden or 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
| var myFunc; | |
| var num = 0; | |
| if (num === 0){ | |
| myFunc = function(theObject) { | |
| theObject.make = "Toyota"; | |
| theObject.year = "2003"; | |
| return theObject; | |
| }; | |
| } | |
| var mycar = {make:"Honda", year:"1993"}; | |
| console.log(mycar); | |
| myFunc(mycar); | |
| console.log(mycar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment