Understanding JS Notes 07 – Odds and Ends


Nothing big hear. Just talking through having large bits of data initialized and not to be intimidated by it.

Finding out what something is

typeof: returns the type of something. arrays have problems here since it’s an object. here we could use something like Object.prototype.toString.call(array) to see if it’s an array or not.

instanceof can tell you if something is part of a prototype chain

Strict Mode

JS can be rather flexible or loose with its rules. We can use something strict mode by using

"use strict"

at the top of a file or top of a function. One thing that happens for example in strict mode is that you cannot set a var without defining it first.

var person;
persom = {}

Works in regular JS, but it strict mode it would throw a persom is not defined errror.