Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Alex
@cyberpunk1971
Hi all. I was wondering if someone could explain in more detail about global variables
var myGlobal = 10 Did I initialize or define that variable? I'm a little confused on that.
ok nvm, i just answered my own question
Alex
@cyberpunk1971
Can someone help me with a javascript question please?
Gersho
@Gersho
if it's within my knowledge$
Alex
@cyberpunk1971
is function(num) a thing in js?
Gersho
@Gersho
you mean anonymous functions ?
Alex
@cyberpunk1971
idk
i'm going through the lessons
the solution was easy, basically given to you, but I just want to know how it was arrived at
Gersho
@Gersho
you mean the fact that it's
function(arg){
//do things
}

instead of 
function myFunction(arg){
//do things
}
could you link the lesson please ?
or give it's name
Alex
@cyberpunk1971
sure hang on
Gersho
@Gersho
ok
so your question is about what part ?
this one ?
changed = change(10);
Alex
@cyberpunk1971
well first, is processed = processArg(7); a global variable?
or a variable at all?
that's the solution
Gersho
@Gersho
processed is a variable
processArg is a function (called with () )
Alex
@cyberpunk1971
ah ok, i just reallized that haha
Gersho
@Gersho
processed was declared on line 12, it's part of the main body of the script so yes it is a global variable
Alex
@cyberpunk1971
so, processed has already been assigned a variable is that correct
ok
it's value is 0, correct?
Gersho
@Gersho

the line evaluates as:
the variable processed is equal to the result of the function processArg when we give it an argument of 7

we then need to check what happens in the function

function processArg(num) {
  return (num + 3) / 5;
}
so the function return as result (7+3)/5
so that would be 2
Alex
@cyberpunk1971
is that because the global is evaluated first?
if that's the correct term
Gersho
@Gersho
the function is evaluated first, so we can know what to put in the variable processed
scope (the "range" of a variable) is relevant to know if you can access it, it doesn't affect priority of events
Alex
@cyberpunk1971
well if the function is eval first, how does it know to include 7?
Gersho
@Gersho
oooh
i understand
Alex
@cyberpunk1971
maybe i can explain my question better5
better
Gersho
@Gersho

when we write

function processArg(num) {
  return (num + 3) / 5;
}

the function is established, but not called

Alex
@cyberpunk1971
so, it's basically waiting for information?
which we give it
Gersho
@Gersho
it's waiting to be called, and it need an argument (7) in this case
Alex
@cyberpunk1971
in the form of processed = processArg(7);
Gersho
@Gersho
yes, because we want that result to go to processed
Alex
@cyberpunk1971
ok
now, the other part of my question...........
the function(num) is waiting for info, which is 7
Gersho
@Gersho
well it's not really "waiting" it's just that until it's called, it's code is not run