1. You can't push to an array and sort it in the same line, at least, not like this:
array.push(entry).sort();It just tells you Uncaught TypeError: undefined is not a function.
2. If you try to push to a variable that you've declared, but haven't initiated as an array, you get an error: "Uncaught TypeError: cannot read property "push" of undefined".
3. You don't have to pass variables to functions for the functions to use and modify them. For example:
var testvar = 02;
var testfunc = function(){
console.log(testvar);
testvar = 3;
console.log(testvar);
}
testfunc();
console.log(testvar);
Simply results in this being printed to the console:
2
3
3
The 2 is testvar, being logged from within the function, even though it was not passed as a parameter.
The first 3 is testvar, being logged from within the function, after the function has modified it.
The second 3 is testvar, being logged from outside the function, which proves that it remains modified even outside the function.
To an experienced coder, this might seem like second nature, but to a beginner, it's important conceptual development. Scope!
4. Say you're making a function that you want to take two parameters: a number, and an array. You then call the function and pass it a number and another number. You think of the first number as the first parameter, and the second number as the only item in an array. The function will take this to mean that both of the things you passed it are actually part of the array parameter. So, make sure you use brackets when you're passing the parameter that's supposed to be an array.
