Show Menu
Cheatography

JavaScript Cheat Sheet (DRAFT) by

The bases of JavaScript.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

The language itself

JavaScript was created to make websites more intera­­ctive.
It's an interp­­reted, weak and dynamic language.
JavaScript a functi­onnal and object­­-o­r­i­ented progra­­mming language.
It is garbage collected and function arguments are always passed by value.

Language enviro­nnement

JavaScript is a text-based language that does not need any conversion before being executed.
It is executed instantly by a type of program that interprets the code called a parser.
To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a .js extension) and then reference that file inside the HTML document using an empty script element with a src attrib­ute.It's also cross-­pla­tform.

Data Structure

Array
Stack
Linked List
Queue
Binary Tree
Binary Search Tree
Heap
Hashing
Graph

Loop

for
loops through a block of code a number of times
for/in
loops through the properties of an object
for/of
loops through the values of an iterable object
while
loops through a block of code while a specified condition is true
do/while
also loops through a block of code while a specified condition is true

Syntax and data struct­ure

consol­e.l­og(x)
to print x
let x = ...
create a variable
const x
non mutable variable
typeof x
type of the variable
Conditions
if(con­dition)
if (condi­tion) else
if(con­dition) else if (another condition
x == y
returns true if x and y are equal
x === y
returns true if x and y are identical
x!=y
Returns true if x and y are not equal
x !== y
Returns true if x and y are not identical
x>=y
Returns true if x is greater than or equal to y
x>y
Returns true if x is greater than y
x<=y
Returns true if x is less than or equal to y
x<y
Returns true if x is less than y
x || y
Returns true if either x or y are true
x && y
returns true if x and y are true

Functi­ons­/Me­thods

function nameof­you­rfu­cti­on(){}
to call a fuction
push()
Appends new elements to the end of an array.
unshift()
Adds one or more items to the beginning of an array.
pop()
Removes the last item from the array
shif()
Removes the first item from the array
length()
number of elements in an array
sort()
Sort an array in place
reverse()
reverses an array
replac­e(a,b)
to replace a by b
split()
Split a string into substrings using the specified separator and return them as an array
toLowe­rCase()
Converts all the alphabetic characters in a string to lowercase.
splice()
change the contents of an array by removing or replacing existing elements and/or adding new elements
concat()
concat­enates (joins) two or more arrays
join()
creates and returns a new string by concat­enating all of the elements in an array
existsSync
Returns true if the path exists