Please help me explain functions in detail

Please help me explain functions in detail
0.0 0

#1

i can call simple functions with arguments and sum their arguement but i dont fully undertsand functions behavior e.g

function dosomething(){
  return something;
}
function dosmetnelse(){
dosomething() //how will this behave
return answer;
}

what i dont understand is how the dosomething() function we behave inside the dosmetnelse function. will the return value of dosomething() affect the return value of dosmetnelse(). explain what will happen, how and why it happens. thank you


#3

YouTube search - JavaScript understanding the weird parts

(I would post the link but do not have access to YouTube website for some odd reason)

There is a great video that explains lexical environment and execution context.


#4

above will now return 0 … the function dosomething() will run but as you have done noting with it it dose nothing to the dosmetnelse function …[quote=“zealsham, post:1, topic:30073”]
function dosomething(){
var something = 5; … Added this line for clarity
return something;
}
[/quote]

now with the line changed above so return is 5 lets look at the function dosmetnelse()

function dosmetnelse(){
var answer = 0;
answer = dosomething(); // answer was 0 now set to value returned from dosomething()
return answer;
}

this time instead of returning 0 it returns 5 …
hope this helps.


#5

wow!!!, thanks this helped me alot. thanks