|Photo by Nathan Smith|
The typeof Operator
typeof 2 // "number" typeof "belladonna" // "string"
Be careful how you use it, though. The return values might not be what you expect, and are of limited use. I highly recommend reading this fantastic article by Angus Croll about the typeof operator, including ways of improving on it.
Truth and Equality
Here are two great articles that cover the topic enjoyably:
A terse summary of true/false values:
- False: undefined, null, false, 0, NaN, ""
- True: Everything else, including all objects — even empty arrays (which are objects) and the object returned by new Boolean(false).
A brief summary of equality operators:
- ==/!= (abstract): Use with caution, as these will coerce the operand types which can lead to suprising results (many people suggest avoiding them entirely).
- ===/!== (strict): If the operand types don't match, will always evaluate to false. Primitives (number, boolean, string) are compared by value, objects by id, and NaN/null/undefined don't equal each other (NaN doesn't even equal itself).
Or, if you prefer your knowledge delivered via A/V:
The debugger Statement
Instead of manually setting breakpoints within your in-browser debugger each time, you can add a debugger statement anywhere in your code that will cause your debugger to stop there. Simply:
debugger;Next up: We finally get to Ember/Handlebars-specific debugging!