KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
First Example: In the following example: http://jsfiddle.net/maniator/ScTAW/4/ I have this js: var storage = (function () { var store = []; return { "add": function (item) { store.push(item); }, "get": function () { return store; } }; }()); storage.add('hi there') console.log(storage, storage.get(), storage.add('hi there #2')); And here is what gets printed to the console: Object ["hi there", "hi there #2"] undefined One would think that the console should only say: Object ["hi there"] undefined becase the second push did not happen until after the value was logged, therefore it should not be displayed. Second Example: In the following example: http://jsfiddle.net/maniator/ScTAW/5/ I am using the same storage variable but I log like so: storage.add('hi there') console.log(storage, storage.get(), (function() { storage.add('hi there #2'); console.log('TESTING'); })()); What gets printed to the console is: TESTING Object ["hi there", "hi there #2"] undefined hmmmm well that is odd now isnt it? One could expect to see: Object ["hi there"] undefined TESTING Why is this happening? What is going on behind the scenes of the console logging mechanism?
Tags (comma-separated)
Save Edits
Cancel