\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Manon Gerrd (manongerard)} \pdfinfo{ /Title (javascript.pdf) /Creator (Cheatography) /Author (Manon Gerrd (manongerard)) /Subject (JavaScript Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{89D0FE} \definecolor{LightBackground}{HTML}{F0F9FE} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{JavaScript Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Manon Gerrd (manongerard)} via \textcolor{DarkBackground}{\uline{cheatography.com/195339/cs/40896/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Manon Gerrd (manongerard) \\ \uline{cheatography.com/manongerard} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 5th November, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{1.44 cm} x{6.56 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Data types}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Primitive types}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Number & Number value (integers and floating point) except big integer \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} BigInt & Large integer\{\{nl\}\}Notation: number literal and an n suffix {\emph{e.g.}} -3000000n \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} String & String of characters\{\{nl\}\}Notation: between single or double quotes \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{Boolean} & Boolean - {\emph{true}} or {\emph{false}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} Symbol & Unique identifier \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{Undefined} & No value assigned \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} Null & Deliberate non-value \tn % Row Count 14 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Object}}} \tn % Row Count 15 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Function} \tn % Row Count 16 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Array} \tn % Row Count 17 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Date} \tn % Row Count 18 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{RegExp\{\{bb\}\}} \tn % Row Count 19 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Error} \tn % Row Count 20 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comments}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{// or /* */} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{string}}.length & Returns the length of a string \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\emph{string}}.charAt(index) & Returns the character at the index \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\emph{string}}.concat(string1, string2, ..., stringX) & Concatenates two or more strings \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} {\emph{string}}.match(regex) & Returns an array of all matches, or null if no match \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} {\emph{string}}.replace(old, new) & Retruns a new string where {\emph{old}} has been replaces by {\emph{new}} \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} {\emph{string}}.search(regex) & Returns the position of the first match, or -1 if no match \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} {\emph{string}}.substring(start, end) & Returns a string containing the characters from start to end (not included) \tn % Row Count 20 (+ 4) % Row 7 \SetRowColor{white} {\emph{string}}.toLowerCase() & Returns the string converted to lowercase \tn % Row Count 23 (+ 3) % Row 8 \SetRowColor{LightBackground} {\emph{string}}.toUpperCase() & Returns the string converted to uppercase \tn % Row Count 26 (+ 3) % Row 9 \SetRowColor{white} "age:" + age + " years" \{\{fa-arrows-h\}\} \textbackslash{}`age: \$\{age\} years\textbackslash{}` & Template literal: allows you to write strings with embedded expressions more succinctly \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String (cont)}} \tn % Row 10 \SetRowColor{LightBackground} {\bf{Escape character}} : \textbackslash{} & \textbackslash{}', \textbackslash{}", \textbackslash{}\textbackslash{}, (\textbackslash{}b, \textbackslash{}f, \textbackslash{}n, \textbackslash{}r, \textbackslash{}t, \textbackslash{}v) \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Boolean}} \tn % Row 0 \SetRowColor{LightBackground} false, 0, empty strings ( "" ), NaN, null, and undefined & interpreted as {\emph{false}}, the rest as {\emph{true}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Boolean(expr) & Explicit conversion to Boolean \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array}} \tn % Row 0 \SetRowColor{LightBackground} {\emph{e.g}} const {\emph{array}} = {[}"a", 10, "c"{]} & Create an array \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\emph{array}}.length & {\bf{Sets}} or returns the number of elements in an array \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Can assign any properties to array, like indices. The only "magic" is that length will be automatically updated when you set a particular index.\{\{nl\}\}This can create sparse array} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} {\emph{array}}{[}index{]} \{\{fa-arrows-h\}\} {\emph{array}}.at(index) & Returns the array at the index \tn % Row Count 12 (+ 3) % Row 4 \SetRowColor{LightBackground} {\emph{array}}.concate(string1, string2, ..., stringX) & Concatenates two or more arrays \tn % Row Count 15 (+ 3) % Row 5 \SetRowColor{white} {\emph{array}}.every(fct, value) & Returns true if every element pass the test, otherwise false \tn % Row Count 18 (+ 3) % Row 6 \SetRowColor{LightBackground} {\emph{array}}.flat(depth) & Concatenates sub-array elements \tn % Row Count 20 (+ 2) % Row 7 \SetRowColor{white} {\emph{array}}.foreach(fct, value) & Calls a function for each array element \tn % Row Count 22 (+ 2) % Row 8 \SetRowColor{LightBackground} {\emph{array}}.indexOf() & Search the array for an element and returns its position \tn % Row Count 25 (+ 3) % Row 9 \SetRowColor{white} {\emph{array}}.lastIndexOf() & Search the array for an element, starting at the end, and returns its position \tn % Row Count 29 (+ 4) % Row 10 \SetRowColor{LightBackground} {\emph{array}}.pop() & Removes the last element of an array, and returns that element \tn % Row Count 33 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Array (cont)}} \tn % Row 11 \SetRowColor{LightBackground} {\emph{array}}.push(item1, item2, ..., itemX) & Adds new elements to the end of an array, and returns the new length \tn % Row Count 4 (+ 4) % Row 12 \SetRowColor{white} {\emph{array}}.sort() & Sorts the elements of an array \tn % Row Count 6 (+ 2) % Row 13 \SetRowColor{LightBackground} {\emph{array}}.toString & Converts an array to a string, and returns the result \tn % Row Count 9 (+ 3) % Row 14 \SetRowColor{white} {\emph{array}}.valueOf() & Returns the primitive value of an array \tn % Row Count 11 (+ 2) % Row 15 \SetRowColor{LightBackground} {\emph{array}}.filter(function(currentValue, index, arr), thisValue) & Creates a new array filled with elements that pass a test provided by a function. \tn % Row Count 16 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Index starts at 0 like in Java or C \newline Arrays are not limited in type of elements} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{RegExp}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\seqsplit{https://www.w3schools.com/js/js\_regexp.asp}} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Date}} \tn % Row 0 \SetRowColor{LightBackground} new Date() & Create the current date and time \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} new Date({\emph{date string}} | year, month, {\emph{{[}day, hours, minutes, seconds, ms{]}}} | {\emph{milliseconds}}) & Create a specific date and time \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} Date.now() & Returns the number of milliseconds since January 1, 1970 \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} {\emph{date}}.parse() & Parses a date string and returns the number of milliseconds since {\bf{January 1, 1970}} \tn % Row Count 15 (+ 5) % Row 4 \SetRowColor{LightBackground} {\emph{date}}.get{\emph{{[}UTC{]}}}{[}Date | FullYear | Month | Day | Hours | Minutes | Seconds | Milliseconds | Time{]}() & Geters \tn % Row Count 20 (+ 5) % Row 5 \SetRowColor{white} {\emph{date}}.set{\emph{{[}UTC{]}}}{[}Date | FullYear | Month | Hours | Minutes | Seconds | Milliseconds | Time{]}() & Seters \tn % Row Count 25 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-warning\}\}JavaScript counts months from 0 to 11 and days from 0 to 6\{\{nl\}\}{\emph{date string}} format : \{\{nl\}\}- ISO: YYYY{\emph{{[}-MM-DDTHH:MM:SSZ{]}}}\{\{nl\}\}- short: MM/DD/YYYY\{\{nl\}\}- long: MMM DD YYYY} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Class (similar to Java)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{JavaScript offers the class syntax that's very similar to languages like Java. \newline \newline class Person \{ \newline constructor(name) \{ \newline this.name = name; \newline \} \newline sayHello() \{ \newline return `Hello, I'm \$\{this.name\}!`; \newline \} \newline \} \newline const p = {\emph{new}} Person("Maria"); \newline console.log(p.sayHello());} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{`this` refers to the person object} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.68 cm} x{4.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Arithmetic operators (similar to C/Java)}} \tn % Row 0 \SetRowColor{LightBackground} x + y (numeric) & Adds x and y together \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x (numeric or string) + y (string) & Concatinates x and y together \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} x - y & Subtracts y from x \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} x * y & Multiplies x and y together \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} x / y & Divides x by y \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} x \% y & x modulo y: the remainder when x is divided by y \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} x ** y & x to the power of y \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} x++, ++x & Increment x (postfix and prefix) \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} x-{}-, -{}-x & Decrement x (postfix and prefix) \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Same operator precedence as usual} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.32 cm} x{5.68 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Assignment operators (similar to C/Java)}} \tn % Row 0 \SetRowColor{LightBackground} x = y & Sets x to the value of y \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x {\emph{op}}= y & Same as x = x {\emph{op}} y \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} x:{\emph{number}} & size.x = {\emph{number}} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparison operators (similar to C/Java)}} \tn % Row 0 \SetRowColor{LightBackground} x \textgreater{} y & Returns true if x is greater than y \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} x \textgreater{}= y & Returns true if x is greater than or equal to y \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} x \textless{} y & Returns true if x is less than y \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} x \textless{}= y & Returns true if x is less than or equal to y \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} x == y & Returns true if x and y are equal\{\{nl\}\}Note: performs type coercion \tn % Row Count 14 (+ 4) % Row 5 \SetRowColor{white} x != y & Returns true if x and y are not equal\{\{nl\}\}Note: performs type coercion \tn % Row Count 18 (+ 4) % Row 6 \SetRowColor{LightBackground} x === y & Returns true if x and y are equal in value and type \tn % Row Count 21 (+ 3) % Row 7 \SetRowColor{white} x !== y & Returns true if x and y are not equal in value or type \tn % Row Count 24 (+ 3) % Row 8 \SetRowColor{LightBackground} {\emph{condition}} ? {\emph{exprIfTrue}} : {\emph{exprIfFalse}} & Returns {\emph{exprIfTrue}} if {\emph{condition}} is true, {\emph{exprIfFalse}} otherwise \tn % Row Count 28 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-warning\}\} Strings are compared alphabetically} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.68 cm} x{6.32 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bitwise operators (similar to C/Java)}} \tn % Row 0 \SetRowColor{LightBackground} x \& y & x AND y \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x | y & x OR y \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textasciitilde{}x & NOT x \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} x \textasciicircum{} y & x XOR y \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} x \textless{}\textless{} y & x left shift of y \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} x \textgreater{}\textgreater{} y & x right shift of y \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} x \textgreater{}\textgreater{}\textgreater{} y & x unsigned right shift of y \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Type operators}} \tn % Row 0 \SetRowColor{LightBackground} typeof & Returns the type of a variable \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{instanceof} & Returns true if an object is an instance of an object type \tn % Row Count 3 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Number}} \tn % Row 0 \SetRowColor{LightBackground} parseInt(string, radix) & Parses the string into an integer \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} parseFloat(string, radix) & Parses the string into a floating-point number \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Number(value) & Parses the value into a number if possible \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} NaN & "Not a number" value \tn % Row Count 9 (+ 1) % Row 4 \SetRowColor{LightBackground} Infinity & Positive or negative infinity value \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} Math.{\emph{function}}() & Math library has a lot of math functions \tn % Row Count 13 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{e.g.}} abs, cbrt, ceil, cos, exp, floor, log, log10, max, min, pow, random, round, sign, sin, sqrt, tan,...} \tn % Row Count 16 (+ 3) % Row 7 \SetRowColor{white} Math.{\emph{constant}}\{\{nl\}\}{\emph{e.g.}} E, PI, ... & Math library has a lot of math constants \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} {\emph{e.g.}} 0b1010, 0o12, 10, 0xA, 0.1e2 & Prefixes to indicate the base or an exponent suffix \tn % Row Count 21 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Symbol}} \tn % Row 0 \SetRowColor{LightBackground} Symbol(expr) & Create a unique Symbol with key expr \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Symbol.for(expr)} & Return the Symbol with the key expr, if it doesn't exists a new Symbol is created and returned. \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \seqsplit{Symbol.keyFor(symbol)} & Returns the string key corresponding to symbol \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Many functions similar to string also exists, they call string's function} \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Object}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{JavaScript objects can be thought of as collections of key-value pairs. They are hashes. They do not have fixed \newline shapes - properties can be added, deleted, re-ordered, mutated, or dynamically queried at any time. Objects keys are always {\bf{strings}} or {\bf{symbols}}. \newline \newline const obj = \{ \newline name: "Carrot", \newline for: "Max", \newline details: \{ \newline color: "orange", \newline size: 12, \newline \}, \newline fullDescr: function() \{ \newline return this.name + " for " + this.for; \newline \} \newline \}; \newline \newline Object properties can be accessed using dot ( . ) or square brackets ( {[}{]} ). {\emph{e.g.}} obj.name or obj{[}"name"{]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A method is a function stored as a property.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Function}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{{\bf{Function Declaration}} \newline % Row Count 1 (+ 1) `function fctName({\emph{args}}) \{ {\emph{code}} \}` \newline % Row Count 2 (+ 1) Like in Python, it is possible to assign a default value to the arguments \newline % Row Count 4 (+ 2) {\bf{Anonymous functions}} \newline % Row Count 5 (+ 1) `const {\emph{var}} = (function ({\emph{args}}) \{ \newline % Row Count 6 (+ 1) {\emph{code}} \newline % Row Count 7 (+ 1) \});` \newline % Row Count 8 (+ 1) Use `{\emph{var}}() \{\}` \newline % Row Count 9 (+ 1) `function` is not mandatory \newline % Row Count 10 (+ 1) {\bf{Function Invocation}} \newline % Row Count 11 (+ 1) The code inside the function will execute when "something" invokes (calls) the function: \newline % Row Count 13 (+ 2) - When an event occurs (when a user clicks a button) \newline % Row Count 15 (+ 2) - When it is invoked (called) from JavaScript code \newline % Row Count 17 (+ 2) - Automatically (self invoked) \newline % Row Count 18 (+ 1) {\bf{Arrow functions}} \newline % Row Count 19 (+ 1) `product = (a, b) =\textgreater{} a * b;`% Row Count 20 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.76 cm} x{6.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} let {\emph{var}} & Declare a block scope local variable \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} const {\emph{var}} & Declare a block scope variable whose value is never intended to change\{\{nl\}\}It cannot be reassigned, therefore it must be initialized \tn % Row Count 7 (+ 5) % Row 2 \SetRowColor{LightBackground} var {\emph{var}} & Declare a variable, not block-scoped -\textgreater{} discouraged in modern JavaScript \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-warning\}\} different that in C/Java: let and const declared variables occupy the entire scope they are defined in, and are in a region known as the temporal dead zone before the actual line of declaration. \newline JavaScript is dynamically typed (like Python), for let can change the type through reassignment} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Control structures (similar to C)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{- {\bf{if and else}} \newline \{\{bb = 1\}\} \newline if ({\emph{cdt}}) \{ \newline {\emph{code}} \newline \} else if ({\emph{cdt}}) \{ \newline {\emph{code}} \newline \} else \{ \newline {\emph{code}} \newline \} \newline \newline - {\bf{while}} \newline while ({\emph{cdt}}) \{ \newline {\emph{code}} \newline \} \newline \newline - {\bf{do ... while}} \newline do \{ \newline {\emph{code}} \newline \} while ({\emph{cdt}}); \newline \newline - {\bf{for loop}} \newline for ({\emph{init}}; {\emph{condition}}; {\emph{update}}) \{ \newline {\emph{code}} \newline \} \newline \newline - {\bf{for ... of}} \newline It iterates over iterables, most notably arrays, \newline for (const value of array) \{ \newline {\emph{code}} \newline \} \newline \newline - {\bf{for ... in}} \newline It visits all enumerable properties of an object. \newline for (const property in object) \{ \newline {\emph{code}} \newline \} \newline \newline - {\bf{switch}} \newline switch(variable/expression) \{ \newline case value1: \newline // body of case 1 \newline break; \newline case value2: \newline // body of case 2 \newline break; \newline case valueN: \newline // body of case N \newline break; \newline default: \newline // body of default \newline \} \newline break works like in C/Java. If you don't add a break statement, execution will "fall through" to the next level. \newline Comparison using ===, cases can be any expression \newline \newline - {\bf{throw}} \newline Errors can be thrown using the throw statement. \newline throw new Error({\emph{string}}); \newline \newline - {\bf{try ... catch}} \newline try \{ \newline {\emph{code}}; \newline \} catch (e) \{ \newline console.error({\emph{string}}, e); \newline \} \newline There's no conditional catch in JavaScript — if you only want to handle one type of error, you need to catch everything, identify the type of error using instanceof, and then rethrow the other cases. \newline try \{ \newline {\emph{code}}; \newline \} catch (e) \{ \newline if (e instanceof RangeError) \{ \newline {\emph{code}} \newline \} else \{ \newline throw e; \newline \} \newline \} \newline \newline - {\bf{return}} \newline \newline - {\bf{continue}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.12 cm} x{6.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Logical operators}} \tn % Row 0 \SetRowColor{LightBackground} x \&\& y & Returns true if both x and y are true \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} x || y & Returns true if x or y is true \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} !x & Returns true if x is false \tn % Row Count 5 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.016 cm} x{3.024 cm} x{1.224 cm} x{0.936 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{HTML events}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{\textless{}{\emph{element}} {\emph{event}}="{\emph{some JavaScript}}"\textgreater{}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{Window Event Attributes}} & inside \textless{}body\textgreater{} & & \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \seqsplit{onafterprint} & onbeforeprint & \seqsplit{onbeforeunload} & \seqsplit{onerror} \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{onhashchange} & onmessage & \seqsplit{onoffline} & \seqsplit{ononline} \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} onpagehide & onpageshow & \seqsplit{onpopstate} & \seqsplit{onresize} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} onstorage & onunload & & \tn % Row Count 12 (+ 1) % Row 6 \SetRowColor{LightBackground} {\bf{Form Events}} & in form elements & & \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} onblur & onchange & \seqsplit{oncontextmenu} & \seqsplit{onfocus} \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} oninput & oninvalid & \seqsplit{onreset} & \seqsplit{onsearch} \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} onselect & onsubmit & & \tn % Row Count 20 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{{\bf{Keyboard Events}}} \tn % Row Count 21 (+ 1) % Row 11 \SetRowColor{white} onkeydown & onkeypress & \seqsplit{onkeyup} & \tn % Row Count 23 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{{\bf{Mouse Events}}} \tn % Row Count 24 (+ 1) % Row 13 \SetRowColor{white} onclick & ondblclick & \seqsplit{onmousedown} & \seqsplit{onmousemove} \tn % Row Count 27 (+ 3) % Row 14 \SetRowColor{LightBackground} onmouseout & onmouseover & \seqsplit{onmouseup} & \seqsplit{onwheel} \tn % Row Count 29 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{{\bf{Drag Events}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{2.016 cm} x{3.024 cm} x{1.224 cm} x{0.936 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{8.4cm}}{\bf\textcolor{white}{HTML events (cont)}} \tn % Row 16 \SetRowColor{LightBackground} ondrag & ondragend & \seqsplit{ondragenter} & \seqsplit{ondragleave} \tn % Row Count 3 (+ 3) % Row 17 \SetRowColor{white} ondragover & ondragstart & \seqsplit{ondrop} & \seqsplit{onscroll} \tn % Row Count 5 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{4}{x{8.4cm}}{{\bf{Clipboard Events}}} \tn % Row Count 6 (+ 1) % Row 19 \SetRowColor{white} oncopy & oncut & \seqsplit{onpaste} & \tn % Row Count 8 (+ 2) % Row 20 \SetRowColor{LightBackground} {\bf{Media Events}} & Inside \textless{}audio\textgreater{}, \textless{}embed\textgreater{}, \textless{}img\textgreater{}, \textless{}object\textgreater{} and \textless{}video\textgreater{} & & \tn % Row Count 12 (+ 4) % Row 21 \SetRowColor{white} onabort & oncanplay & \seqsplit{oncanplaythrough} & \seqsplit{oncuechange} \tn % Row Count 15 (+ 3) % Row 22 \SetRowColor{LightBackground} \seqsplit{ondurationchange} & onemptied & \seqsplit{onended} & \seqsplit{onerror} \tn % Row Count 17 (+ 2) % Row 23 \SetRowColor{white} \seqsplit{onloadeddata} & \seqsplit{onloadedmetadata} & \seqsplit{onloadstart} & \seqsplit{onpause} \tn % Row Count 19 (+ 2) % Row 24 \SetRowColor{LightBackground} onplay & onplaying & \seqsplit{onprogress} & \seqsplit{onratechange} \tn % Row Count 22 (+ 3) % Row 25 \SetRowColor{white} onseeked & onseeking & \seqsplit{onstalled} & \seqsplit{onsuspend} \tn % Row Count 24 (+ 2) % Row 26 \SetRowColor{LightBackground} \seqsplit{ontimeupdate} & onvolumechange & \seqsplit{onwaiting} & \tn % Row Count 26 (+ 2) % Row 27 \SetRowColor{white} \mymulticolumn{4}{x{8.4cm}}{{\bf{Misc Events}}} \tn % Row Count 27 (+ 1) % Row 28 \SetRowColor{LightBackground} ontoggle & Fires when the user opens or closes the \textless{}details\textgreater{} element & & \tn % Row Count 31 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}