Javascript


Types

string

String

"This is a string!"

number

Integer or float

64

null

null value

null

double

64 bit float (number with decimal point)

64.0

bigint

64 bit signed integer

64L

boolean

Boolean value (either true or false)

true

Arithmetic operators

+

Addition

Unary positive, makes number positive

-

Subtraction

Unary negative, makes number negative

*

Multiplication

/

Division

%

Modulo (remainder of division)

**

Indice

++

Increment

--

Decrement

Assignment operators

=

Equals

+=

a+=b is a=a+b

-=

a-=b is a=a-b

*=

a*=b is a=a*b

/=

a/=b is a=a/b

%=

a%=b is a=a%b

**=

a**=b is a=a**b

&=

a&=b is a=a&b

|=

a|=b is a=a|b

^=

a^=b is a=a^b

>>=

a>>>=b is a=a>>>b

<<=

a><<=b is a=a><<b

Comparison operators

==

Is equal to

===

Has equal value and type to

!=

Is not equal to

!=

Doesn't have equal value or type to

>

Greater than

<

Less than

>=

Greater than or equal to

<=

Less than or equal to

?

Ternary operator; executes one of two possibilities based on boolean value

isTrue ? "Yes" : "No"

Bitwise operators

&

Bitwise AND

|

Bitwise OR

^

Bitwise XOR

<<

Arithmetic shift left (shifts all the bits one space to the left, essentially multiplying it by 2)

>>

Logical shift right (shifts all the bits one space to the right, essentially dividing it by 2)

>>>

Unsigned logical shift right (shifts all the bits one space to the right, essentially dividing it by 2)

~

Bitwise NOT

Logical operators

&&

AND operator

||

OR operator

!

NOT operator

Type operators

typeof

Returns the type of a variable

instanceof

Returns true if an object is an instance of an object type

Miscellaneous operators

.

Applies method to object
Applies a state to an enum type

[]

Initialises an array
References an array's index

,

Used to separate parameters

()

Defines a list
Denotes parameters of a function

{}

Defines a block

:

Used for switch cases

Used in declaring a class instance's variable's value

=>

Defines a lambda expression

x = a => a+1;

""

Declares a string

''

Declares a string

;

Declares end of a line of code

Key word

const

Used to declare constant that can't be redeclared throughout entire code

var

Used to declare a variable

let

Used to declare an object that can't be redeclared within current block

extends

Used for including a class in another class, creating polymorphism

super

Used for referencing the class' superclass

case

Used for cases in a switch

Used for delcaring states in an enum

implements

Used for including an interface in another interface or in a class, creating polymorphism

enum

Used for defining an enum; a datatype that denotes a "state" of something

interface

Used for declaring an interface; like a class but has no variables and methods can be empty

abstract

Used for declaring an abstract class or method, which is a class or method that is only accessible through its subclasses and is defined in its subclass

switch

Used for declaring switch statements

double

Used for declaring doubles (also known as floats, or numbers with decimal place)

boolean

Used for declaring booleans

int

Used for declaring integers

String

Used for declaring strings

static

Used for declaring methods that do not depend on the state of the class

do

Used for declaring loop in a while loop

throw

Used for throwing error messages

throws

Used for denoting methods that throw specific errors

char

Used for declaring characters

void

Used for declaring that a method does not return a specific value

this

Used for referring to the original constructor of a class on which a new object is being created

new

Used for declaring new objects from a class

private

Used for declaring private classes or methods, that cannot be interacted with by other classes

public

Used for declaring public classes or methods, that can be interacted with by other classes

if

Used for declaring if statements

while

Used for declaring while loops

for

Used for declaring for loops

try

Used for declaring try catch

except

Used for declaring exception case

else

Used for declaring else statements

import

Used for importing foreign classes for use in code

return

Used to give a final value at the end of a function or method

break

Used to tell compiler to end the loop

final

Used to denote a class with no subclasses or a function that can't be overwritten in a subclass

Statements

catch

Executes code on failed try statement

catch (Exception exception)
 code

class

Declares a class (class name must have a capital letter at start)

class Class {
 code;
}

for

Loops code for a set amount iterations or for every object in list

for (initialization; condition; update) {
 code;
}

for (let variable in array) {
 code;
}

if

Executes code on true condition

if (condition) {
 code;
}

import

Includes foreign file's functions

import function from file;

else

Executes when an if statement is false or if a try statement has no error

else {
 code;
}

switch

Displays different outcomes based on the value within the expression

switch (expression) {
case x:
  code;
break;
case y:
  code;
break;
}

try

Attempts to execute code and ignores on error

try {
 code;
}

try (declaration) {
 code;
}

finally

Executes code at end of try statement

finally {
 code;
}

enum

Declares an enum

enum enum {
 code;
}

function

Declares a function

function function(args) {
 code;
}

var function =function(args) {
 code;
}

Promise

Declares a promise (basically an asynchronous try-catch, or then-catch in javascript terms)

new Promise((resolve, reject) => {  //code showing conditional paths for both resolve() and reject() });

var function =function(args) {
 code;
}

then

Represents actions to take when a promise is fufilled

while

Loops code on true condition

while (condition) {
 //code to loop
}

do {
 //code when true
}
while (condition);

Popup functions

confirm()

Creates boolean prompt that displays a string, returns the answer the user selects

confirm(string);

prompt()

Creates string prompt that displays a string, returns the answer the user wrote

prompt(string);

alert()

Creates an alert popup that displays a string

alert(string);

Default functions

Methods

toString

toFixed

charAt

split

concat

toLowerCase

toUpperCase

toFixed

toFixed

String properties

length

Returns length of a string

Math.PI

Math.E

Math.SQRT2

Math.SQRT1_2

Math.LN2

Math.LN10

Math.LOG2E

Math.LOG10E

DOM

Document.getElementById()

Document.getElementsByTagName()

Document.getElementsByClassName()

.innerHTML

.attribute

Commenting

//

Used to tell compiler the rest of this line is not to be compiled

/*

Opens a multi line comment

*/

Closes a multi line comment

constructor

Constructor of a class (method to make objects of a class)

Obfuscation

Minification

Packing

Encoding

Base64

Encoding that uses alpha-numeric encoding as well as + and /. It uses = as padding to ensure every string has a length that is a multiple of 4

Hex

Encoding that contains numbers 0 to 9 as well as letters A, B, C, D, E, and F, that maps ASCII characters to their hex representation

Rot13

Encoding that translates each letter to the letter 13 letters in front, a form of caeser cypher