Javascript Cheat Sheet

This is not meant to be a comprehensive list of javascript functions and operators or regex info.  This is more for stuff you do in javascript that may not be completely obvious.  There might be more than one way to do it, but the "best practice" has been selected.

Does object obj contain key?
    if (key in obj)
Is variable a an array?
    Array.isArray(a)    Object.prototype.toString.call( a ) === '[object Array]'
    $.isArray(a)
    _.isArray(a)
Remove a key from an object
    delete obj.key
Is variable x defined?
    var x;
    x === undefinded
Is variable x set?
    var x = null;
    x === null
Is variable n a number?
    typeof n === 'number'
Return keys of an object obj as an array
    Object.keys(obj)

No comments:

Post a Comment