\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{tegdsd12} \pdfinfo{ /Title (basic-programming.pdf) /Creator (Cheatography) /Author (tegdsd12) /Subject (Basic Programming 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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{Basic Programming Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{tegdsd12} via \textcolor{DarkBackground}{\uline{cheatography.com/121770/cs/22409/}}} \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}tegdsd12 \\ \uline{cheatography.com/tegdsd12} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 14th April, 2020.\\ Updated 14th April, 2020.\\ 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*}{3} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Variable Instantiation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{let variableName = value} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} let & required keyword to initialize a variable \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{variableName} & arbitrary name, no spacing, must contain letter, no punctuaction, cannot use reserved keywords, camel-cased \tn % Row Count 7 (+ 4) % Row 3 \SetRowColor{white} = & assign \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} value & any data type \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \seqsplit{camel-case} & no spacing between words, every word except the first is capitalized e.g a red balloon -\textgreater{} aRedBalloon \tn % Row Count 13 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{the value assigned can be referenced in later parts of the program through variableName. \newline Only one value can be assigned to one variable, i.e one instantiation per variable, if let var1 = 'string' previously, cannot let var1 = 2 again later in the code} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.59264 cm} x{3.38436 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operators}} \tn % Row 0 \SetRowColor{LightBackground} + & plus \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & minus \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & multiply \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} / & divide (5/2 = 2.5) \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \% & remainder (5 \% 2 = 1) \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textgreater{} & more than \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \textless{} & less than \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \textgreater{}= & more than or equals \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \textless{}= & less than or equals \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} i++ & i = i + 1 \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} i-{}- & i = i - 1 \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} == & equal value \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} === & equal value and data type \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} i (+,-,*,/) = value & shorthand for i = i + value, i= i - value, etc \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.68655 cm} x{0.9154 cm} x{2.97505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Data Types}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{String} & \seqsplit{'string'} & Anything in quotes. If there are quotations inside the string, use a different type of quotation ( ' and " ) \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \seqsplit{Number} & 1, 23, 400 & number \tn % Row Count 7 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{Boolean} & true, false & true/false value \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{Character} & 'a', '2' & single input \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{Undefined} & let \seqsplit{variable} & variable instantiated but not assigned a value \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} Null & & variable not defined(instantiated) \tn % Row Count 15 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.04517 cm} x{3.93183 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Array}} \tn % Row 0 \SetRowColor{LightBackground} Array & {[}'string', 2, true{]} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{- initialized with square brackets \newline - can contain all data types, including arrays and objects \newline - ordered list of values, starting from index 0 to refer to first element \newline - get item in array by referring to its index (array{[}0{]} gets 'string', array{[}1{]} gets 2)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.64701 cm} x{4.32999 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Object}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Object} & let object = \{ key1: value1, key2: value2 \} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{similar to array, but replace index with key(string) \newline can contain all data types, including arrays and objects \newline refer to objects in 2 ways \newline 1. object.key1 gets value1 \newline 2. object{[}'key2'{]} gets value2. when using square brackets, put the key in string format} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Function Example}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{let num1 = 1; \newline let num2 = 20; \newline let result = addTogether(num1, num2); \newline \newline {\emph{num1 and num2 becomes firstNum and secondNum respectively}} \newline {\emph{if no return value, calculations done in the function cannot be carried out of the function}} \newline \newline function addTogether(firstNum, secondNum) \{ \newline return firstNum + secondNum; \newline \} \newline \newline result will get the returned value of 21} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Loops}} \tn % Row 0 \SetRowColor{LightBackground} if & if condition is true, execute block \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} else & must be used with {\bf{if}}, executes if {\bf{if}} condition is false \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} if else & additional if statements after the first if statement \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} while & while condition is true, keep executing block \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} for & for (let i = 0; i\textless{} 10; i++), a condensed while loop \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} for & for (let number of numbers) \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} for & for (let number in numbers) \tn % Row Count 12 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{loop (condition) \{ \newline execute code in block \newline \} \newline \newline {\bf{for}} \newline \newline {\bf{for}} has multiple uses \newline 1.a condensed while loop \newline for (let i = 0; i\textless{} 10; i++) \{\} \newline 2. To loop through an array/object \newline let numbers = {[}20, 30, 10, 50, 70{]}; \newline for (let number of numbers) \{ \newline use value \newline each loop uses {\bf{number}} = 20, then 30, 10 ... \newline \} \newline for (let numbers in numbers) \{ \newline use index/key \newline each loop uses {\bf{number}} = 0, then 1, 2 ... \newline to get value, use numbers{[}number{]} (object{[}index{]}) \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{function foo(param1, param2) \{ return param1 + param2\}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} function & keyword to instantiate function \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} foo & function name, use to describe function purpose, camel-case \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} param1, param2 & parameters to put into function (optional) \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} return & value to get back from function (optional) \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{functions are called with brackets -\textgreater{} foo() \newline if function has parameters, function must be called with parameters -\textgreater{} foo(param) \newline parameters are assigned to new names for usage in the function (see below)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}