Javascript Fundamentals Part 2

Welcome to Javascript Fundamentals Part 2. Javascript is such an endless pit of code this will be somewhat of an infinite series of parts.

To recap, I covered data types, loops, and a few conditional structures in part 1 of this series. I’ve decided to cover object method and properties – a few basic ones.

You’ve probably heard this one before.

Everything in Javascript is an object.

Well this is true – except it gets really confusing because there are other types in Javascript.

  • String
  • Number
  • Array
  • Boolean

So what data type is this supposed to be?


// Is this an array data type
// Or an object data type?
var isThisAnObject = new Array();

I guess it would be proper to say that an array is an object, so instead of separating the two keywords to distinguish a data type – you can just call it an “Array Object”.

Arrays are objects because we can perform or execute methods and properties on arrays like we would an object. Consider the following.


// let's use an object literal instead
// to create an array

var arrayObject = [1, 2, 3, 4, 5];

// let's get the length of our
// defined array

console.log(arrayObject.length); // will output 5

The length property is accessed using object dot notation, we simply chain a property to our target array object.

What about an array method?

It’s the same deal, we use object notation to access an object method.


var arrayObjectSort = [4, 3, 1, 2, 5];

console.log(arrayObjectSort.sort()); 

// will output [1, 2, 3, 4, 5]

The sort() method will do the work for us simply by “envoking” or “calling” the sort() method. Running any additional property or method on an any type of object works exactly the same. So once you get the hang of it, it’s the same all across the board.


var arrayObjectReverse = [1, 2, 3, 4, 5];

console.log(arrayObjectReverse.reverse());

// will output [5, 4, 3, 2, 1]

Javascript has a lot of built in object properties and methods – instead of memorizing all of them I would focus more on a thorough understanding of objects work. Just like what were doing here.

What if I have some property of method that’s not built-in?

Well in this case you will have to write one of your own – and this is where things get really interesting. But were jumping ahead here. In order to effectively write our own methods and properties, we also need a thorough understanding of how functions work. Note that functions themselves are also object or “first class citizens” in that they can be passed around like the other data types mentioned. Yeah I know what you’re thinking, this is getting super complicated. Well I’m not going to lie, it is and it’s just something you have to grind through as a programmer.