0% found this document useful (0 votes)
1K views

Javascript Cheatsheet Pag1

This cheat sheet provides a summary of JavaScript programming concepts including: - Number, string, array, boolean, and other data types and their properties and methods - Regular expressions syntax and properties - Date object methods for manipulating dates and times - Common array methods for modifying, iterating, filtering and more - Functions and their properties and methods - Math object with common mathematical methods - Objects and their properties

Uploaded by

Rober Smith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Javascript Cheatsheet Pag1

This cheat sheet provides a summary of JavaScript programming concepts including: - Number, string, array, boolean, and other data types and their properties and methods - Regular expressions syntax and properties - Date object methods for manipulating dates and times - Common array methods for modifying, iterating, filtering and more - Functions and their properties and methods - Math object with common mathematical methods - Objects and their properties

Uploaded by

Rober Smith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CHEAT SHEET

JAVASCRIPT WEB PROGRAMMING


Created by @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 + equivalent n .length string size n .length number of elements


n .NEGATIVE_INFINITY - equivalent METHODS METHODS
n .MAX_VALUE largest positive value s .charAt(index) char at position [i] b .isArray(obj) check if obj is array
n .MIN_VALUE smallest positive value n .charCodeAt(index) unicode at pos. b .includes(obj, from) include element?
n .EPSILON diff between 1 & smallest >1 s .fromCharCode(n1, n2...) code to char n .indexOf(obj, from) nd elem. index
n .NaN not-a-number value s .concat(str1, str2...) combine text + n .lastIndexOf(obj, from) nd from end
METHODS
b .startsWith(str, size) check beginning s .join(sep) join elements w/separator
s .toExponential(dec) exp. notation b .endsWith(str, size) check ending a .slice(ini, end) return array portion
s .toFixed(dec) xed-point notation a .concat(obj1, obj2...) return joined array
b .includes(str, from) include substring?
s .toPrecision(p) change precision MODIFY SOURCE ARRAY METHODS
n .indexOf(str, from) nd substr index
b .isFinite(n) check if number is nite a .copyWithin(pos, ini, end) copy elems
n .lastIndexOf(str, from) nd from end
b .isInteger(n) check if number is int. a .ll(obj, ini, end) ll array with obj
n .search(regex) search & return index
b .isNaN(n) check if number is NaN a .reverse() reverse array & return it
n .localeCompare(str, locale, options)
n .parseInt(s, radix) string to integer a .sort(cf(a,b)) sort array (unicode sort)
a .match(regex) matches against string
n a .splice(ini, del, o1, o2...) del&add elem
.parseFloat(s, radix) string to oat s .repeat(n) repeat string n times
ITERATION METHODS
s .replace(str|regex, newstr|func)
r Regexp() = /.+/ig ai .entries() iterate key/value pair array
s .slice(ini, end) str between ini/end
PROPERTIES ai .keys() iterate only keys array
s .substr(ini, len) substr of len length
n .lastIndex index to start global regexp ai .values() iterate only values array
s .substring(ini, end) substr fragment
s .ags active ags of current regexp a .split(sep|regex, limit) divide string CALLBACK FOR EACH METHODS

b .global ag g (search all matches) s .toLowerCase() string to lowercase b .every(cb(e,i,a), arg) test until false
b .ignoreCase ag i (match lower/upper) s .toUpperCase() string to uppercase b .some(cb(e,i,a), arg) test until true
b .multiline ag m (match multiple lines) s a .map(cb(e,i,a), arg) make array
.trim() remove space from begin/end
b .sticky ag y (search from lastIndex) a .lter(cb(e,i,a), arg) make array w/true
s .raw`` template strings with ${vars}
b .unicode ag u (enable unicode feat.) o .nd(cb(e,i,a), arg) return elem w/true
s .source current regexp (w/o slashs) n
d Date() .ndIndex(cb(e,i,a), arg) return index
METHODS
METHODS .forEach(cb(e,i,a), arg) exec for each
a .exec(str) exec search for a match
n .UTC(y, m, d, h, i, s, ms) timestamp o .reduce(cb(p,e,i,a), arg) accumulative
b .test(str) check if regexp match w/str
n .now() timestamp of current time o .reduceRight(cb(p,e,i,a), arg) from end
CLASSES
n .parse(str) convert str to timestamp ADD/REMOVE METHODS
. any character \t tabulator
n .setTime(ts) set UNIX timestamp o .pop() remove & return last element
\d digit [0-9] \r carriage return
n .getTime() return UNIX timestamp n .push(o1, o2...) add element & return length
\D no digit [^0-9] \n line feed
\w any alphanumeric char [A-Za-z0-9_] UNIT SETTERS (ALSO .setUTC*() methods) o .shift() remove & return rst element
\W no alphanumeric char [^A-Za-z0-9_] n .setFullYear(y, m, d) set year (yyyy) n .unshift(o1, o2...) add element & return len
\s any space char (space, tab, enter...) n .setMonth(m, d) set month (0-11) UNSHIFT PUSH
\S no space char (space, tab, enter...) n .setDate(d) set day (1-31) [1,2,3]
\xN char with code N [\b] backspace b Boolean() = true / false SHIFT POP
n .setHours(h, m, s, ms) set hour (0-23)
\uN char with unicode N \0 NUL char n .setMinutes(m, s, ms) set min (0-59) no own properties or methods
CHARACTER SETS OR ALTERNATION
n .setSeconds(s, ms) set sec (0-59)
[abc] match any character set n .setMilliseconds(ms) set ms (0-999) f Function() = function(a, b) { ... }
[^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, arg1, arg2...) change this
GROUPING n .getMinutes() return minutes (0-59) o .apply(newthis, arg1) with args array
(x) capture group (?:x) no capture group n .getSeconds() return seconds (0-59) o .bind(newthis, arg1, 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 x 0 or more times {0,} n .getTimezoneOffset() offset in mins n NaN (not-a-number) r regular expresion
x+ preceding x 1 or more times {1,} s .toLocaleDateString(locale, options) s string f function
x? preceding x 0 or 1 times {0,1} s .toLocaleTimeString(locale, options) b boolean (true/false) o object
x{n} n ocurrences of x s .toLocaleString(locale, options) a array undened
x{n,} at least n ocurrences of x s .toUTCString() return UTC date only available on ECMAScript 6
x{n,m} between n & m ocurrences of x s .toDateString() return American date n static (ex: Math.random())
ASSERTIONS s .toTimeString() return American time n non-static (ex: new Date().getDate())
x(?=y) x (only if x is followed by y) s .toISOString() return ISO8601 date argument required
x(?!y) x (only if x is not followed by y) s .toJSON() return date ready for JSON argument optional
CHEAT SHEET

JAVASCRIPT WEB PROGRAMMING


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

Math o Object() = {key: value, key2: value2} s Set() WeakSet only obj as items
PROPERTIES PROPERTIES PROPERTIES

n .E Euler's constant o .constructor return ref. to object func. n .size return number of items
n .LN2 natural logarithm of 2 METHODS METHODS
n .LN10 natural logarithm of 10 o .assign(dst, src1, src2...) copy values s .add(item) add item to set ws
n .LOG2E base 2 logarithm of E o .create(proto, prop) create obj w/prop b .has(item) check if item exists ws
n .LOG10E base 10 logarithm of E o .deneProperties(obj, prop) b .delete(item) del item & return if del ws
n .PI ratio circumference/diameter o .deneProperty(obj, prop, desc) .clear() remove all items from set
n .SQRT1_2 square root of 1/2 o .freeze(obj) avoid properties changes ITERATION METHODS
n .SQRT2 square root of 2 o .getOwnPropertyDescriptor(obj, prop) si .entries() iterate items
METHODS a .getOwnPropertyNames(obj) si .values() iterate only value of items
a .getOwnPropertySymbols(obj)
n .abs(x) absolute value CALLBACK FOR EACH METHODS
o .getPrototypeOf(obj) return prototype
n .cbrt(x) cube root .forEach(cb(e,i,a), arg) exec for each
b .is(val1, val2) check if are same value
n .clz32(x) return leading zero bits (32)
b .isExtensible(obj) check if can add prop m Map() WeakMap only obj as keys
n .exp(x) return ex
b .isFrozen(obj) check if obj is frozen
n .expm1(x) return ex-1 PROPERTIES
b .isSealed(obj) check if obj is sealed n .size return number of elements
n .hypot(x1, x2...) length of hypotenuse a .keys(obj) return only keys of object
n .imul(a, b) signed multiply o .preventExtensions(obj) avoid extend
METHODS

n .log(x) natural logarithm (base e) o .seal(obj) prop are non-congurable m .set(key, value) add pair key=value wm
n .log1p(x) natural logarithm (1+x) o .setPrototypeOf(obj, prot) change prot o .get(key) return value of key wm
n .log10(x) base 10 logarithm INSTANCE METHODS
b .has(key) check if key exist wm
n .log2(x) base 2 logarithm b .delete(key) del elem. & return if ok wm
b .hasOwnProperty(prop) check if exist .clear() remove all elements from map
n .max(x1, x2...) return max number
b .isPrototypeOf(obj) test in another obj
n .min(x1, x2...) return min number ITERATION METHODS
b .propertyIsEnumerable(prop)
n .pow(base, exp) return baseexp mi .entries() iterate elements
s .toString() return equivalent string
n .random() oat random number [0,1) mi .keys() iterate only keys
s .toLocaleString() return locale version
n .sign(x) return sign of number mi .values() iterate only values
o .valueOf() return primitive value
n .sqrt(x) square root of number CALLBACK FOR EACH METHODS
ROUND METHODS
p Promise() .forEach(cb(e,i,a), arg) exec for each
n .ceil(x) superior round (smallest) METHODS
n .oor(x) inferior round (largest) p .all(obj) return promise Symbol()
n .fround(x) nearest single precision p .catch(onRejected(s)) = .then(undef,s) PROPERTIES
n .round(x) round (nearest integer) p .then(onFullled(v), onRejected(s)) s .iterator species default iterator
n .trunc(x) remove fractional digits p .race(obj) return greedy promise (res/rej) s .match species match of regexp
TRIGONOMETRIC METHODS p .resolve(obj) return resolved promise s .species species constructor function
n .acos(x) arccosine p .reject(reason) return rejected promise METHODS
n .acosh(x) hyperbolic arccosine s .for(key) search existing symbols
n .asin(x) arcsine p Proxy() Reect same methods (not func) s .keyFor(sym) return key from global reg
n .asinh(x) hyperbolic arcsine METHODS
n .atan(x) arctangent o .apply(obj, arg, arglist) trap function call g Generator() = function* () { ... }
n .atan2(x, y) arctangent of quotient x/y o .construct(obj, arglist) trap new oper METHODS
n .atanh(x) hyperbolic arctangent o .deneProperty(obj, prop, desc) o .next(value) return obj w/{value,done}
n .cos(x) cosine o .deleteProperty(obj, prop) trap delete o .return(value) return value & true done
n .cosh(x) hyperbolic cosine o .enumerate(obj) trap for...in .throw(except) throw an error
n .sin(x) sine o .get(obj, prop, rec) trap get property
o .getOwnPropertyDescriptor(obj, prop) Others
n .sinh(x) hyperbolic sine
n .tan(x) tangent o .getPrototypeOf(obj) FAST TIPS

n .tanh(x) hyperbolic tangent o .has(obj, prop) trap in operator var declare variable
o .ownKeys(obj) let declare block scope local variable
o .preventExtensions(obj) const declare constant (read-only)
JSON
o .set(obj, prop, value) trap set property func(a=1) default parameter value
METHODS
o .setPrototypeOf(obj, proto) func(...a) rest argument (spread operator)
n .parse(str, tf(k,v)) parse string to object
(a) => { ... } function equivalent (fat arrow)
n .stringify(obj, repf|wl, sp) convert to str globals
`string ${a}` template with variables
METHODS
e Error() 0bn binary (2) number n to decimal
o eval(str) evaluate javascript code 0on octal (8) number n to decimal
PROPERTIES
b isFinite(obj) check if is a nite number 0xn hexadecimal (16) number n to decimal
s .name return name of error b isNaN(obj) check if is not a number
s .message return description of error for (i in array) { ... } iterate array, i = index
n parseInt(s, radix) string to integer for (e of array) { ... } iterate array, e = value
n parseFloat(s, radix) string to oat
EvalError(), InternalError(), RangeError(), URIError(), class B extends A () { } class sugar syntax
ReferenceError(), SyntaxError(), TypeError() s encodeURIComponent(URI) = to %3D
s decodeURIComponent(URI) %3D to =

You might also like