Function execution priority in javascript.
Below I posted my code. Code functionality working fine but I am not sure about statement execution flow.
so after executing isValiduser() i am able to get role id but only when i write that to two different function and call one by one. is there any way i can execute function in the same order as I placed.
I know my question is quite confusing but please reply for more info.
I want step 1 execute first then step 2
One way to ensure the sequence would be to wrap the call in a conditional, though I have a feeling maybe some kind of a callback would be more elegant. For example, if I had
function foo() {
// do stuff
}
function bar() {
// do other stuff
}
function baz() {
foo();
bar();
}
and I wanted to be absolutely certain that foo ran before bar I could do something like
function foo() {
// do stuff
return true;
}
function baz() {
if ( foo() ) {
bar();
}
}
if I call 3 different functions as step 1 as first function step 2 as second and third one start where i wrote sc.load();
but all three i need to handle in 3 different button click then it’s working by but not as I was trying above.
If logic structures alone do not give you enough control a callback should work. IMHO it’s a little bit beyond newbie level, but is something well worth learning because they come in useful often. Basically it’s a way to pass a function to a function where the code runs synchronistically