There's something bugging my mind recently and sorry for the bad title. Assume I create a little snippet.
Let's assume that someone was currently using my snippet. He pushes a certain value into an array and blah.
Now he wants to check the value of the variable [ic]push[/ic]. But sadly it returns [ic]undefined[/ic].
I think you'd understand what I mean now.
I need an answer; why did it always returns undefined unless there's a [ic]return[/ic] statement behind the code inside the function?
- Code:
[panda=js]function pushArray(arr, str)
arr.push(str);
}
Let's assume that someone was currently using my snippet. He pushes a certain value into an array and blah.
- Code:
[panda=js]var blah = [1];
var push = pushArray(blah, 2);
Now he wants to check the value of the variable [ic]push[/ic]. But sadly it returns [ic]undefined[/ic].
- Code:
[panda=js]// pushArray module code here
// his code here
console.log(push); // returns undefined
I think you'd understand what I mean now.
I need an answer; why did it always returns undefined unless there's a [ic]return[/ic] statement behind the code inside the function?