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
Gersho
@Gersho
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
Alex
@cyberpunk1971
and then the cpu says, "I need to print out the answer to (7 + 3) / 5"
Gersho
@Gersho
and put it in that variable
Alex
@cyberpunk1971
and that is where function(num) comes into play
Gersho
@Gersho
yes, it calls the function
Alex
@cyberpunk1971
i think I understand it now. you're awesome dude
thanks @Gersho
CamperBot
@camperbot
cyberpunk1971 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 439 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
you can call it multiple times
var blabla = processArg(5);
var foo = processArg(8);
Alex
@cyberpunk1971
another question I have is where/when would I use something like this?
is this for front end? back end? or what?
Gersho
@Gersho
don't worry you'll see plenty of those
it's a basic of coding, it'll be everywhere
Alex
@cyberpunk1971
ok
Gersho
@Gersho
it's usefull to reuse code
Alex
@cyberpunk1971
so is processArg a common term?
Gersho
@Gersho
for exemple my exemple earlier
no i was reusing your exemple ^^
Alex
@cyberpunk1971
ok
Gersho
@Gersho
you name your function as you want it (preferably something to know what it does)
Alex
@cyberpunk1971
is function(num) a common term?
Gersho
@Gersho
the use of a function like that is to re-use it, this one is only 1 line, but if you have a lot, you don't want to retype it)
function is a keyword
Alex
@cyberpunk1971
ok
i was wondering if (num) was common
Gersho
@Gersho
the values in the () are usually called arguments (you can have multiple)
Alex
@cyberpunk1971
i seem to remember something like that is was
ok
i'm pretty new to js