December 29, 201312 yr what is the is the purpose for using parseInt and parseFloat? and what does actually the return function does? for example on this code here: var foo = doSomething(5 , 6); var bar = doSomething(1, 5); function doSomething(paramOne, paramTwo) { paramOne = paramOne + 5; paramOne = paramOne + 1; paramOne = paramOne -1; return paramOne + paramTwo; } alert(foo); alert(bar);
December 30, 201312 yr The return statement 'returns' a value/object/statement etc. When you use the return statement, it makes the value that you return available when/if you ask for it. Think of if like a persons hand passing round some paper with information on it. The hand passing the information but another persons hand needs to pick it up and look at it for it to be read/understood. Examples: function a() { console.log("A value"); } function b() { return 'A value'; } calling a() output: A value calling b() output: nothing UNLESS you use something like console.log(b()); parseint will take a string and return an integer. Javascript can handle numbers a bit unexpectedly to watch out. parse float does the same but for floating point numbers. If you don't understand float/numbers etc look up Javascript types Edited December 30, 201312 yr by Mr Ben
Create an account or sign in to comment