Design Portfolio


JavaScript: Understanding the Weird Parts (Part 8)

Arrays: Collections of Anything

var arr = [1, 2, 3];
  • JavaScript arrays are 0 indexed; they start at 0.
  • Since JavaScript is dynamically typed, we can mix and match types within an array.

arguments and spread

  • arguments - the parameters you pass to a function
    • The keyword arguments is a special term JavaScript uses to contain all the arguments.
    • arguments contains a list (that looks like array) of all the values of parameters that have been passed.
function greet(fname, lname, ... other) {}
  • Additional parameters that are not explicityly defined in the function call get wrapped up in a array other.

Syntax Parsers

  • Syntax parsers read the code and decide if it's valid, and determine what the code is trying to do.
    • They go through the code character by character.

Automatic Semicolon Insertion

  • Semi-colons are optional in core JavaScript.
  • carriage return - finishing a line, hitting return on the keyboard is an invisible character but the syntax parser can see it.
    • If you use a carriage return, the syntax parser will automatically inject a semi-colon.
  • The syntax parser automatically inserts a semi-colon whereever it expects one to be.
  • So, always insert your own semi-colons.
  • Don't use a carriage return after return if you want to return something after.


return {
    name: Ella


{name: Ella}
  • See how the Do includes the { right after return, while the Don't uses a carriage return after return.