/    Sign up×
Community /Pin to ProfileBookmark

simple question about javascript

Hello people,
even though i’m quite old, I recently started to learn computer programming languages
(i’m studying also php and looking something about c sharp)

I’m tryed to learn javascript expecially to use it in google app script service…

Question could seem stupid, but it’s very important for me because i fell quite well now inside a single function, but i have a lot of doubts when i have to connect more functions inside a scritp tag.

The doubts I have are about the asynchronious factor that i don’t know excatly how it works (i mean aoutomatically, out of your control)

I will write a little scheme with pseudo-code for make my question clear.

<script>

call_function_1 () {

// do some job on the client (no callback here – it’s simple a function)

return a result

}

// line 1

var my_variabile = call_function_1 ()

// line 2

// do other things with the var my_variabile and the dom

// call other functions…

// or whatelse

</script>

I need to know if it’s possbile that javascript not execute at first the call_function_1
and if it’s possibile that javascript not wait the result of this function

before go ahead and start to work on line 2, calling other functions or whatelse

in other words am I syncronioyus in this way? (it’s what i want)

tks very much

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@wbportFeb 07.2017 — JavaScript doesn't exist in a vacuum, it is part of a webpage, is referred to by a webpage, or is called by another program. Your [B]line 1[/B] might be a function started when someone clicked a button.

Also, JavaScript may be in the head (usual place) or in the body of a page. If you want to put your function out of the way, put it in near the end of the head. Scripts in the body would run from top to bottom (outside of loops, function calls, etc.) but could use a function in the head. If you had a function to determine the difference between a given date and current date to insert it (via [B]document.write[/B] for example), you might define myDateFunction(parm) in the head while in the body you would use it like:[CODE]<body>
............................
My grandson is
<script>
myDateFunction("Jan 12, 2003")
</script>
old.
........</body>[/CODE]
Or, insert your wedding date for text like [B]We have been married for [/B] before your inline script. You wouldn't have to change your page at each birthday or anniversary.

FWIW, I have had my share of grey hair for a while now.
Copy linkTweet thisAlerts:
@andylorenzauthorFeb 08.2017 — I have read a lot of stuff, but this point is not well described

I knew visual basic that is not very different than google app script if you use it inside office (the same is for basic or javascipt or phyton inside open office)

In visual basic you could check every moment the flux of the code and the execution of the application, you could follow step by step what happened (line by line) watching changes in real time

The debugging in javascript is not the same, you have some tools in google, but there is no equivalence with the kind of debugging you could do in visual basic

Outside google app script enviroment there is something in the console browser in google chrome or mozilla that can be very helpfull, they are not easy to use (so pheraps i don't know well hot to use at the best), but in any case they don't seem able to do the same exactly things was easy to follow and check in visual basic enviroment concept (ide was surelly the bes thigns of that structure)

So, since you can follow exactly what happen inside the computer processes, is not easy to understand how it works

What process start first? what process wait the answer before go ahead? what process works asynchonios? in what moment you have assigned the value of variabile for value, this kind of question

Of course when you have a IDE able to go step by step showing you everything is happening inside the computer process is more simple understand how it works

When we speak about asynchornious, i personally don't get exactly the concept, i know (because i read it) ajax request are by default asynchronious (if you don't turn false the option) and other browser window function like setinterval... what about other things? who know.. this is the point..

I know (because i read) that you can use callback in parameter for dealing with this kind of situation

What i don't know if in other cases, more or less by default, you are in the synchronious situations

that it mean you call a function and the system wait the final result return of this function before go ahead, process the code usually line by line waiting the result every time... and soso...

If I am in google and i'm running two or more functions they are before the call to the server (that is google.scritp.run api function), since i get datas and elaborate datas to send server side as parameters from these client functions, i need to know if is possibile that this last server function can start before, can start before only some times (for example if it's busy the structure)...

of course if it can start, i have 99 times the right result and 1 time unidefinited, null, string empty or something like this.
Copy linkTweet thisAlerts:
@Strider64Feb 08.2017 — Google Chrome Developer tools is great in debugging javascript and is pretty interactive. You can stop the code at a certain line of code, watch variables and even tell what is going on with the script with console.log written directly in the script (I like this feature the best for it will work with other browsers as well).

I just converted trivia game over to vanilla (pure) javascript from JQuery -> https://github.com/Strider64/Trivia-IntoXication-Game

I'm still working on it.
Copy linkTweet thisAlerts:
@wbportFeb 08.2017 — When I was working on my most recent page "irvtest", hitting F12 in Firefox gave me access to the console and debugger. After setting up a breakpoint and starting the page, local variables in the function were displayed automatically, global variables or a specific occurrence of array variable could be added to the list. Google Chrome and other browsers probably work similarly.

My functions and global variables are in the head, but some simple code to show the last modified date is near the end of the body.
×

Success!

Help @andylorenz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...