I have a question regarding why the following returns inconsistent values
(function(ab, $, undefined ) {
ab.cool = {
nice: {
funky: {
sweet: false
}
}
};
var reVal = ab.cool.nice.funky.sweet;
reVal = true;
console.log(reVal); //equals true
console.log(ab.cool.nice.funky.sweet); //equals false
}( window.ab = window.ab || {}, jQuery ));
I would have thought that both SHOULD return the same value true ?
Can someone please explain why this occurs ? Are they considered different properties ?
What’s happening is that the value of
ab.cool.nice.funky.sweetgets copied toreVal. This would not happen if you tried to copyab.cool.nice.funkytoreVal, since both symbols would then reference the same object.This differentiation is the product of treating value types, such as booleans or integers, differently than reference types which in javascript basically means objects.
Check this for more info: http://docstore.mik.ua/orelly/webprog/jscript/ch11_02.htm