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 interactive.
It's an interpreted, weak and dynamic language.
JavaScript a functionnal and object-oriented programming language.
It is garbage collected and function arguments are always passed by value. |
Language environnement
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 attribute.It's also cross-platform. |
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 structure
console.log(x) |
to print x |
let x = ... |
create a variable |
const x |
non mutable variable |
typeof x |
type of the variable |
Conditions |
if(condition) |
if (condition) else |
if(condition) 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 |
Functions/Methods
function nameofyourfuction(){} |
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 |
replace(a,b) |
to replace a by b |
split() |
Split a string into substrings using the specified separator and return them as an array |
toLowerCase() |
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() |
concatenates (joins) two or more arrays |
join() |
creates and returns a new string by concatenating all of the elements in an array |
existsSync |
Returns true if the path exists |
|