Ryan Hayes
Tri
7/14/15
var x = 2;
var y = 1 + 1;
x == y; // true
x === y; // true
x == 20; // false
x === 20; // false
x == "something"; //false
x === "something"; //falseBoth of these check equality
(and "Falsiness")
ˈtro͞oTHēnis/
noun
informal
the quality of seeming or being felt to be true, even if not necessarily true.
(For ===)
(For ==)
Don't do this:
var myVariable = false;
if (myVariable === undefined)
{
// do something
}why?
var myVariable = false;
undefined = false;
if (myVariable === undefined)
{
// Executes!
}Do this:
var myVariable = false;
if (typeof myVariable === 'undefined')
{
// Doesn't execute, since typeof is 'object'
}/* A module that keeps things tidy! */
(function () {
// ... all vars and functions are in this scope only
// still maintains access to all globals
}());Add some parenthesis to keep it tidy...
/* A module that relies on jQuery! */
(function ($, Ember) {
// now have access to globals jQuery (as $) and Ember in this code
}(jQuery, Ember));... now explicitly allow dependencies...
/* A module that others can use as the name */
var RYANSLIBRARY = (function () {
var tempLib = {};
var somethingPrivate = 1;
function privateMethod() {
// ...
}
tempLib.someAwesomeProperty = 1;
tempLib.someMethodYouCanCall = function () {
return "Hey oh!";
};
return tempLib;
}());
RYANSLIBRARY.someMethodYouCanCall(); // Returns "Hey oh!"...now you're a modulin' master! Spread the love!
No, Really -> http://usejsdoc.org/
/**
* Represents a book.
* @constructor
* @param {string} title - The title of the book.
* @param {string} author - The author of the book.
*/
function Book(title, author) {
}