Reputation: 605
I have an object that I am configuring over multiple steps and I am simply to trying to organize the code better. Here is an example:
var myObj = {};
function one(obj) {
//Do a whole bunch of stuff;
obj.count = 0;
}
function two(obj) {
obj.count += 1;
}
one(myObj);
two(myObj);
When function 2 is called, am I guaranteed that obj.count already exists (because function one was completely ran)? I understand there are other ways I could do this, but I am simply wondering about this case and what's happening. These are not async functions either such as a database call or file reader.
Upvotes: 1
Views: 112
Reputation: 53361
Yes, you are guaranteed that obj.count
exists. JavaScript executes synchronously.
Upvotes: 4