You are on page 1of 4

 

CHEAT SHEET

 JA
 JAVASCRIPT WEB PROGRAMMING
Created by @Manz ( http://twitter.com/Manz
http://twitter.com/Manz )
 ) http://www.emezeta.com/

n Number() = 42 s String() = 'text' a Array() = [1, 2, 3]


PROPERTIES PROPERTIES PROPERTIES

n  .POSITIVE_INFINITY
.POSITIVE_INFINITY +∞ equivalent n  .length string size n  .length number of elements
n  .NEGATIVE_INFINITY
.NEGATIVE_INFINITY -∞ equivalent METHODS METHODS
n  .MAX_VALUE largest positive value s .charAt(
.charAt(index
index)) char at position [i] b .isArray(obj
.isArray(obj)) check if obj is array
n  .MIN_VALUE smallest positive value n .charCodeAt(
.charCodeAt(index
index)) unicode at pos. b .includes(
.includes(obj
obj,, from)
from) include element?

n  .EPSILON
n diff between
 .NaN not-a-number 1 & smallest >1
value s .fromCharCode(n1,, n2
.fromCharCode(n1  n2...)
...) code to char n
n from)) find elem. index
.indexOf(obj,, from
.indexOf(obj
s .concat(str1
.concat( str1,, str2
 str2...)
...) combine text + .lastIndexOf(obj
.lastIndexOf( obj,, from)
from) find from end
METHODS
b .startsWith(str
.startsWith( str,, size)
size) check beginning s .join(sep
.join(sep)) join elements w/separator
w/separator
s .toExponential(dec)) exp. notation
.toExponential(dec b .endsWith(str
.endsWith( str,, size
size)) check ending a .slice(ini
.slice(ini,, end)
end) return array portion
s .toFixed(dec
.toFixed( dec)) fixed-point notation b .includes(str
.includes( str,, from)
from) include substring?
a .concat(obj1
.concat( obj1,, obj2...)
obj2...) return joined array
s .toPrecision(p
.toPrecision( p) change precision n .indexOf(str
.indexOf( str,, from
from)) find substr index
MODIFY SOURCE ARRAY METHODS

b .isFinite(n
.isFinite(n) check if number is finite n .lastIndexOf(str
.lastIndexOf( str,, from
from)) find from end
a .copyWithin(pos,, ini,
.copyWithin(pos ini, end)
end) copy elems
b .isInteger(n
.isInteger( n) check if number is int. n a .fill(
ll(obj
obj,, ini
ini,, end
end)) fill array with obj
.search(regex
.search( regex)) search & return index
b .isNaN(n
.isNaN( n) check if number is NaN a .reverse() reverse array & return it
n .localeCompare(str
.localeCompare( str,, locale,
locale, options
options))
n .parseInt(ss, radix
.parseInt( radix)) string to integer a .sort(cf(a,b)
.sort( cf(a,b))) sort array (unicode sort)
a .match(regex
.match( regex)) matches against string
n .parseFloat(ss, radix)
.parseFloat( radix) string to float a .splice(ini
.splice( ini,, del,
del, o1,
o1, o2
o2...)
...) del&add elem
s .repeat(n
.repeat( n) repeat string n times
ITERATION METHODS
s .replace(str
.replace( str||regex,
regex, newstr|
newstr|func)
func)
r Regexp() = /.+/ig ai .entries() iterate key/value pair array
s .slice(ini
.slice(ini,, end
end)) str between ini/end
PROPERTIES ai .keys() iterate only keys array
s .substr(ini
.substr( ini,, len)
len) substr of len length
n .lastIndex index to start global regexp s ai .values() iterate only values array
.substring(ini
.substring( ini,, end)
end) substr fragment
s .flags active flags of current regexp CALLBACK FOR EACH METHODS
b .global flag g (search all matches) as .split(
.split(sep
sep||regex,
regex, string
.toLowerCase() limit
limit)) divide string
to lowercase b .every(cb(e,i,a),, arg
.every(cb(e,i,a) arg)) test until false
b .ignoreCase flag i (match lower/upper)
lower/upper) s .toUpperCase() string to uppercase b .some(cb(e,i,a)
.some( cb(e,i,a),, arg)
arg) test until true
b .multiline flag m (match multiple
multiple lines) s .trim() remove space from begin/end a .map(cb(e,i,a)
.map( cb(e,i,a),, arg)
arg) make array
b .sticky flag y (search from lastIndex) a .filter(
lter(cb(e,i,a)
cb(e,i,a),, arg)
arg) make array w/true
s .raw`` template strings with ${vars
${vars}}
b .unicode flag u (enable unicode feat.) o .find(
nd(cb(e,i,a)
cb(e,i,a),, arg
arg)) return elem w/true
s .source current regexp (w/o slashs) n
d Date() .findIndex(
ndIndex(cb(e,i,a)
cb(e,i,a),, arg)
arg) return index
METHODS
METHODS .forEach(cb(e,i,a)
.forEach( cb(e,i,a),, arg)
arg) exec for each
a .exec(str
.exec(str)) exec search for a match
n .UTC(y, m, d, h, i, s, ms)
.UTC(y ms) timestamp o .reduce(
.reduce(cb(p,e,i,a)
cb(p,e,i,a),, arg
arg)) accumulative
b .test(
.test(str
str)) check if regexp match w/str o .reduceRight(
n .now() timestamp of current time .reduceRight(cb(p,e,i,a)
cb(p,e,i,a),, arg)
arg) from end
CLASSES
n .parse(str
.parse(str)) convert str to timestamp  ADD/REMOVE
 ADD/REMOVE METHODS
. any character \t tabulator
\d digit [0-9] \r carriage return
n .setTime(ts
.setTime( ts)) set UNIX timestamp o .pop() remove & return last element
n .getTime() return UNIX timestamp n .push(o1
.push( o1,, o2...)
o2...) add element & return length
\D no digit [^0-9] \n line feed
\w any alphanumeric char
char [A-Za-z0-9_]
 [A-Za-z0-9_] UNIT SETTERS (ALSO .setUTC*() methods) o .shift() remove & return first element
\W no alphanumeric char
char [^A-Za-z0-9_]
 [^A-Za-z0-9_] n .setFullYear(y
.setFullYear(y, m, d) set year (yyyy) n .unshift(o1
.unshift( o1,, o2
o2...)
...) add element & return len
\s any space char (space, tab, enter...) n .setMonth(
.setMonth(mm, d) set month (0-11) UNSHIFT PUSH

\S
\x
\xNNno space
 char withchar
code(space,
N tab,backspace
[\b] enter...) n .setDate(d) set day (1-31)
.setDate(d b Boolean() = true / false SHIFT [1,2
,2,,3] POP
POP
n .setHours(h
.setHours( h, m, s, ms)
ms) set hour (0-23)
\u
\uNN char with unicode N \0 NUL char n .setMinutes(m
.setMinutes( m, s, ms
ms)) set min (0-59) no own properties or methods
CHARACTER SETS OR ALTERNATION
n .setSeconds(ss, ms
.setSeconds( ms)) set sec (0-59)
[abc
abc]] match any character set n .setMilliseconds(ms
.setMilliseconds( ms)) set ms (0-999) f Function() = function(a, b) { ... }
[^
[^abc
abc]] match any char. set not enclosed UNIT GETTERS (ALSO .getUTC*() methods) PROPERTIES
a|b match a or b n .getDate() return day (1-31) o  .length return number of arguments
BOUNDARIES
n .getDay() return day of week (0-6) s  .name return name of function
^ begin of input $ end of input n .getMonth() return month (0-11) o  .prototype prototype object
\b zero-width word boundary n .getFullYear() return year (yyyy) METHODS
\B zero-width non-word boundary n .getHours() return hour (0-23) o .call(newthis
.call(newthis,, arg1,
arg1, arg2...)
arg2...) change this
GROUPING n .getMinutes() return minutes (0-59) o .apply(
.apply(newthis
newthis,, arg1)
arg1) with args array
(x) capture group (?:
(?:xx) no capture group n .getSeconds() return seconds (0-59) o .bind(
.bind(newthis
newthis,, arg1
arg1,, arg2
arg2...)
...) bound func
\ n reference to group n captured n .getMilliseconds() return ms (0-999)
QUANTIFIERS LOCALE & TIMEZONE METHODS n number d date
x* preceding
preceding x
 x 0
 0 or more times {0,} n .getTimezoneOffset() offset in mins n NaN (not-a-number) r regular expresion

xx+ preceding x
preceding x 0
? preceding x
preceding  x 1
 1 or
 0 or 1more times
times {0,1}{1,} s
s .toLocaleDateString(
.toLocaleDateString(locale
locale,
locale,,,options
.toLocaleTimeString(locale
.toLocaleTimeString( options)
options))
options) b boolean (true/false) of function
s string object
x{n} n ocurrences of x
of x s .toLocaleString(locale
.toLocaleString( locale,, options)
options) a array undefined
x{n,} at least n ocurrences of x
of x s .toUTCString() return UTC date only available on ECMAScript 6
x{n,m} between n & m ocurrences of x of x s .toDateString() return American date n static (ex:
(ex: Math
Math.ran
.random()
dom()))
 ASSERTIONS
 ASSERTIONS s .toTimeString() return American time n non-static (ex:
(ex: new Date().getDat
Date().getDate()
e()))
x(?=
(?=yy) x (only if x is followed by y) s .toISOString() return ISO8601 date argument
argument required
 required
x(?!
(?!yy) x (only if x is not followed by y) s .toJSON() return date ready for JSON argument optional
argument  optional
 

CHEAT SHEET

AVASCRIPT   WEB PROGRAMMING


 JA
 J
Created by @Manz ( http://twitter.com/Manz
http://twitter.com/Manz )
 ) http://www.emezeta.com/

window = Browser global object screen = info about screen / resolution performance = info about performance
PROPERTIES PROPERTIES PROPERTIES

b .closed check if window is closed n  .availTop top-from space available o  .navigation info about redir/type nav
nav..
n .devicePixelRatio ratio vertical size pix n  .availLeft left-from space available o  .timing info about latency-load perf.
b .fullScreen check if window is fullscreen n  .availWidth width space available METHODS
n .innerWidth width size (incl. scrollbar) n  .availHeight height space available n .now() high precision timestamp
n n  .width screen width resolution
n .innerHeight heightsize
.outerWidth width size(incl.
(incl.browser)
scrollbar) n  .height screen height resolution navigator = info about browser
n .outerHeight height size (incl. browser) n  .colorDepth screen color depth (bits) PROPERTIES

n .length number of frames n  .pixelDepth screen pixel depth (bits) b  .cookieEnabled browser cookies on?
s .name inner
.name  inner name of window METHODS n  .doNotTrack DNT privacy enabled?
s .status bottom
.status bottom statusbar text b .lockOrientation(
.lockOrientation(mode
mode||modearray
modearray)) o  .geolocation user-info geolocation
 API/OBJECTS
 API/OBJECTS PROPERTIES
PROPERTIES b .unlockOrientation() remove locks s  .language language in browser
o .applicationCache offfline resources API
.applicationCache o n  .maxTouchPoints max on device
o .console console
.console  console browser API console = unofficial console browser API b  .onLine browser work in online mode?
o .crypto cryptographic
.crypto  cryptographic API METHODS s  .userAgent identify browser of user
o .history session
.history  session page history API .assert(cond,, str1|
.assert(cond str1|obj1
obj1...)
...) set a assert METHODS

o .location information
.location  information about URL API .count(str
.count( str)) count (show number times) n .vibrate(
.vibrate(n
n|pattern
pattern)) use device vibration
o .localStorage storage
.localStorage  storage for site domain .dir(obj
.dir(obj)) show object (expanded debug)
o .sessionStorage storage
.sessionStorage  storage until closed .group() open new message group location = info about current URL
o .navigator information
.navigator  information about browser .groupCollapsed() open new group coll. PROPERTIES

o .performance data
.performance  data about performance .groupEnd() close previous group s  .href full document url
SCREEN PROPERTIES .table(array
.table(array||obj
obj,, colnames
colnames)) show table s  .protocol https: //www.em
 //www.emezeta.com/
ezeta.com/
o .screen information about screen
.screen information .trace() show code trace s  .username https://
https://user
user:pass@www
:pass@www
.timeStamp(str
.timeStamp( str)) put time on timeline s  .password https://user:pass
https://user:pass@www
@www
n .screenX horizontal pos browser/screen
s  .host https://emezeta.com:81
https:// emezeta.com:81 /
n .screenY vertical pos browser/screen PERFORMANCE METHODS
s  .hostname https://emezeta.com
https://emezeta.com:81/
:81/
n .pageXOffset horizontal pixels scrolled .profile(name
le(name)) start performance profile
s  .port https://emezeta.com:81
https://emezeta.com: 81 /
n .pageYOffset vertical pixels scrolled .profileEnd(
leEnd(name
name)) stop perf. profile
s  .pathname http://emezeta.com
http://emezeta.com /42/
 /42/
WINDOW PROPERTIES .time(name
.time(name)) start performance timer
s  .hash http://emezeta.com/#contacto
http://emezeta.com/ #contacto
o .opener window that opened this window
.opener window .timeEnd(name
.timeEnd(name)) stop perf. timer
s  .search http://google.com/
http://google.com/?q=emezeta
?q=emezeta
o .parent parent
.parent  parent of current window/frame LOG LEVEL METHODS
o  .searchParams
.searchParams search params object
o .self this
.self  this window (equal to .window
.window)) .log(str1||obj1
.log(str1 obj1...)
...) output message s  .origin source origin of document url
o .top top
.top  top window of current win/frame .info(str1
.info(str1||obj1
obj1...)
...) output information
METHODS .warn(str1
.warn( str1||obj1
obj1...)
...) output warning onClick="..."(HTML)
onClick="..." (HTML)   .onclick =(JS
= (JS func) 
func)  'click' (Listener)
s .btoa(str
.btoa(str)) encode string to base64 .error(str1
.error(str1||obj1...)
obj1...) output error e events (only popular events)
s .atob(
.atob(str
str)) decode base64 string to text MOUSE EVENTS
.focus() request send window to front window = global interaction func. e  .onClick  e  .onDblClick 
.blur() remove focus from window METHODS
e  .onMouseDown e  .onMouseUp
USER INTERACTION METHODS
o .getSelection(
.getSelection(idid)) return Selection object e e
.postMessage(msg
.postMessage( msg,, dst,
dst, transf)
transf ) send .alert(str
.alert( str)) show message (ok button)  .onMouseEnter
e  .onMouseMove  .onMouseLeave
e  .onMouseOver
o .open(
.open(url
url,, name,
name, options)
options) open popup s .prompt(str
.prompt( str,, def)
def) ask answer to user e  .onMouseOut e  .onWheel
.stop() stop window loading b .confirm(
rm(str
str)) show message (ok, cancel) KEYBOARD EVENTS
b .find(
nd(str
str,, case,
case, back , wrap,
wrap, word,
word, fr,
fr, d) e  .onKeyDown e  .onKeyUp
.print() open print document window history = page history on tab e  .onKeyPress
PROPERTIES
 ANIMATION
 ANIMATION METHODS
METHODS LOAD/OBJECT EVENTS
n .requestAnimationFrame( n  .length number of pages in historytab
.requestAnimationFrame(cb(n)
cb(n))) e  .onDOMContentLoaded e  .onLoad
n  .state return state top history stack 
.cancelAnimationFrame(reqID))
.cancelAnimationFrame(reqID e  .onAbort e  .onError
METHODS
TIMER METHODS e  .onResize e  .onScroll
n .setTimeout(
.setTimeout(f(a...)
f(a...),, ms,
ms, a...) delay&run .back() go prev page (same as .go(-1)
.go(-1))) e  .onBeforeUnload e  .onUnload
.clearTimeout(id)) remove timeout
.clearTimeout(id .forward() go next page (same as .go(1).go(1))) FORM/FIELDS EVENTS

n .setInterval(
.go(n
.go(n) go n page (positive or negative) e  .onBlur e  .onFocus
.setInterval(f(a...)
f(a...),, ms
ms,, a...) run every
.pushState(obj
.pushState( obj,, title,
title, url)
url) insert state e  .onChange e  .onInput
.clearInterval(id
.clearInterval(id)) remove interval .replaceState(obj
.replaceState( obj,, title,
title, url
url)) repl. state e  .onInvalid e  .onSelect
SCREEN METHODS
e  .onReset e  .onSubmit
.scrollBy(x
.scrollBy(x, y) scroll x,y pixels (relative) storage localStorage / sessionStorage  ANIMATION/TRAN
 ANIMATION/TRANSITION
SITION EVENTS
EVENTS

.scrollTo(
.scrollTo(x
.moveBy(x
.moveBy( xx,, yy)) scroll
move x,y pixelsby
window (absolute)
x,y (rel)
PROPERTIES
n  .length number of items in storage
e  .onDragEnter e  .onDragLeave
e  .onDragStart e  .onDragEnd
.moveTo(x
.moveTo( x, y) move window to x,y (abs) METHODS e  .onDragOver e  .onDrag e  .onDrop
.resizeBy(x
.resizeBy( x, y) resize win by x,y (rel) s .key(
.key(nn) return key name on position n  ANIMA
 ANIMATION/TRAN
TION/TRANSITION
SITION EVENTS
EVENTS
.resizeTo(w
.resizeTo( w, h) resize win to WxX (abs) s .getItem(
.getItem(key
key)) return value of item key e  .onAnimationStart e  .onAnimationEnd
STYLESHEET METHODS
.setItem(key,, value
.setItem(key value)) set or update key e  .onAnimationIteration e  .transitionEnd
o .getComputedStyle(elem
.getComputedStyle(elem,, pseudelem)
pseudelem) .removeItem(key
.removeItem( key)) delete item with key
a .matchMedia(
.matchMedia(mediaq
mediaq)) match CSSMQ .clear() delete all items for current site
 

CHEAT SHEET

AVASCRIPT   WEB PROGRAMMING


 JA
 J
Created by @Manz ( http://twitter.com/Manz
http://twitter.com/Manz )
 ) http://www.emezeta.com/

document = Document object e Element() = Element object a Attr() = Attribute object


PROPERTIES PROPERTIES PROPERTIES

s  .characterSet document charset s  .accessKey if exist, shortcut key s .name name of element attribute
s  .compatMode quirks or standard mode o .attributes array of Attr objects s .value value of element attribute
s  .cookie return all cookies doc string o .classList DOMT
DOMTokenList
okenList of classes
s  .designMode return design mode status s  .className classes list to string t DOMTokenList() = List of classes
s  .dir return direction text: "rtl" or "ltr" s  .id id string of element PROPERTIES

s  .doctype return document type (DTD) s  .name name string of element n  .length number of items
s  .domain return document domain s  .tagName HTML tag of element METHODS
s  .documentURI return document URL POSITION, SIZE AND SCROLL PROPERTIES b .contains(
.contains(item
item)) check if item exists
s  .lastModified return date/time modific. n .clientTop top border width element
.clientTop top .add(item)) add item to list
.add(item
s  .origin return document's origin n .clientLeft left
.clientLeft  left border width element s .item(
.item(n
n) return item number
number n  n
s  .readyState return current load status n .clientWidth inner
.clientWidth  inner width element .remove(item
.remove( item)) del item from list
s  .referrer return previous page (referrer) n .clientHeight inner
.clientHeight  inner height element b .toggle(
.toggle(item
item)) del item if exist, add else
s  .title return document title n .scrollTop top-position
.scrollTop  top-position in document
s  .URL return HTML document URL n .scrollLeft left-position
.scrollLeft  left-position in document n Node() = Minor element (elem. or text)
o  .location information about URL n .scrollWidth width
.scrollWidth  width of element PROPERTIES
ELEMENTS PROPERTIES n .scrollHeight height
.scrollHeight  height of element s .baseURI absolute base URL of node
o .activeElement focused element GET/SET HTML CODE PROPERTIES s .namespaceURI namespace of node
o .body return body element s  .innerHTML get/set HTML inside elem s .nodeName name of node
o  .currentScript return active script s  .outerHTML get/set HTML (incl. elem) s .nodeType 1=element, 2=text, 9=doc
o  .defaultView return window element s .nodeValue value of node
METHODS
o  .documentElement first element (root) s .prefix namespace prefix of node
o
o  .head return head element a .closest(selec
.closest(selec)) closest ancestor
.getElementsByClassName(
.getElementsByClassName(class class)) s .textContent text of node and children
o  .scrollingElement first scrollable elem. NAVIGATION PROPERTIES
a .getElementsByTagName( tag) tag)
DOCUMENT ARRAY PROPERTIES
o .querySelector(selec
.querySelector( selec)) return first elem o .childNodes children nodes collection
a .anchors array of images elements
.anchors array a .querySelectorAll(selec
.querySelectorAll( selec)) return elems o .firstChild first children (include text)
a .applets array
.applets  array of applets elements b .matches(selec
.matches( selec)) match with this elem? o .lastChild last children (include text)
a .embeds array
.embeds  array of embeds elements .insertAdjacentHTML(posstr
.insertAdjacentHTML( posstr,, html
html)) o .nextSibling immediate next node
a .forms array
.forms  array of forms elements  ATTRIBUTE
 ATTRIBUTE METHODS
o .previousSibling immediate prev node
a .images array
.images  array of images elements o .parentElement immediate parent elem
b .hasAttributes() exists attributes?
a .links array
.links array of links elements o .parentNode immediate parent node
b .hasAttribute(
.hasAttribute(name
name)) exist attribute?
a .plugins array
.plugins  array of plugins elements o .ownerDocument return document
s .getAttribute(
.getAttribute(name
name)) return value
a .scripts array
.scripts  array of scripts elements METHODS
.removeAttribute(name)) del attribute
.removeAttribute(name
STYLESHEET PROPERTIES
.setAttribute(name
.setAttribute(name,, value
value)) set attrib. o .appendChild(node)) add node to end
.appendChild(node
a .styleSheets
.styleSheets array
 array of style files elem o .cloneNode(child
.cloneNode( child)) duplicate node
CLIENTRECT (POSITION AND SIZES) METHODS
o  .preferredStyleSheetSet
.preferredStyleSheetSet preferred css o .compareDocumentPosition(node
.compareDocumentPosition( node))
o  .selectedStyleSheetSet selected css o .getBoundingClientRect() return pos.
b .contains(node
.contains(node)) node is descendant?
a .getClientRects() return pos/size array
METHODS b .hasChildNodes() node has childs?
o .adoptNode(node)) adopt from ext doc
.adoptNode(node e Event() = Event on action o .insertBefore(newnode,, node)
.insertBefore(newnode node)
o .createAttribute(name
.createAttribute( name)) create Attr obj b .isDefaultNamespace(nsURI
.isDefaultNamespace( nsURI))
PROPERTIES
o .createDocumentFragment() b .isEqualNode(node
.isEqualNode( node)) check if are equal
o .createElement(tag
.createElement( tag)) create Element obj b .bubbles true=bubble, false=captures s .lookupNamespaceURI() ret namesp.
o .createEvent(type
.createEvent(type)) create Event object b .cancelable event is cancelable? s .lookupPrefix() return prefix for a ns
o .createRange() create Range object o .currentTarget current element .normalize() normalize-form children
o .createTextNode( text)
text) create TextNode b .defaultPrevented preventDefault() call o .removeChild(
.removeChild(node
node)) del node & return
o .enableStyleSheetsForSet(name
.enableStyleSheetsForSet( name)) n .detail additional event info o .replaceChild(
.replaceChild(newnode
newnode,, oldnode)
oldnode)
o .importNode(node
.importNode( node,, desc
desc)) import copy n .eventPhase current stage (0-3)
o .getElementById(id
.getElementById( id)) find elem with id b .isTrusted user action or dispatched c ChildNode()
a .getElementsByName(name
.getElementsByName( name)) w/ name o .target reference to dispatched object METHODS

o .getSelection(id
.getSelection( id)) return Selection object n .timeStamp time when was created o .remove() remove specified node
s .type type of event
r ClientRect() = Coords of element METHODS
p ParentNode()
PROPERTIES PROPERTIES
.preventDefault() cancel event
n .top top coord of surrounding rect .stopImmediatePropagation() n .childElementCount number of children
n o .children children elements
n .right
.bottom right coordcoord
bottom of surrounding rect r.
of surrounding .stopPropagation() prevent being called o .firstElementChild first children elem.
n .left left coord of surrounding rect o .lastElementChild last children elem.
t EventTarget (use over elements)
n .width width coord of surrounding rect
METHODS n NonDocumentTypeChildNode()
n .height height coord of surrounding r.r.
.addEventListener(ev,, cb(ev),
.addEventListener(ev cb(ev), capt
capt)) PROPERTIES

.removeEventListener(ev
.removeEventListener( ev,, cb(ev),
cb(ev), capt)
capt) o .nextElementSibling next element
b .dispatchEvent(
.dispatchEvent(ev
ev)) o .previousElementSibling prev element

You might also like