Relearning Javascript the Right Way
Week 2
function setName(obj) {
obj.name = “Nicholas”;
obj = new Object();
obj.name = “Greg”;
}
var person = new Object();
setName(person);
alert(person.name); //”Nicholas”
In Javascript, all functions arguments are passed by value. Since a new object was instantiated within the function, the person object is no longer linked to obj.
null is an object type. Uninstantiated values are undefined. If you want to see what type of object it is, use this formula:
result = variable instanceof constructor
alert(person instanceof Object
Written by Brandon Turner
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Related Tags
#js
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#