# Important methods (math, integers, strings)

## Math

Methods
Math.random() returns a decimal
Math.min(params_int) returns the min number which is in the sequence
Math.max(params_int) returns the max number in the sequence
Math.round() rounds the number to the nearest integer
Math.ceil() rounds the number up to the nearest integer (ceiling/high above)
Math.floor() rounds the number down to the nearest integer (ground/floor)

#### popular constants

Math.E // returns Euler’s number
Math.PI // returns PI
Math.SQRTnum // returns the square root of num

Converting to integer/floats

parseFloat(string/char) self explanatory
parseInt(string/char) self explanatory

toFixed(number_of_digits_after_dot) sets the number of digits of a decimal number after the dot. If number=0, then there are no digits after the space(Whole number). Returns string.
toPrecision(number_rounding_result) Rounds the number to a precision based on the number_rounding_result

Important values
undefined – The undefined property indicates that a variable has not been assigned a value.
nan – not a number (can be a char/string/bool..) useful method isNaN(string/char/int/float ect…)

## Strings

Basic properties

` .length `

retrieves all characters from the string and returns an integer which specifies the amount of char in the given string.

Basic methods:

`charAt(index)`

returns a char specifying the character at a certain index position (index start from 0)

`charCodeAt(index)`

returns a integer specifying the unicode number where the char at the given index is located.

`concat(params)`

concatenates (glues) a string to the previous string( the string specified inside the argument is added to the previous one, multiple strings can be added inside the argument).

`fromCharCode(unicode_num);`

returns a char based on the unicode value argument input.

`indexOf(string/char)`

returns a integer index specifying the index position of the first char inside the argument,

common method

`lastIndexOf(char)`

returns a integer index specifying the index position of the last time the char inside the string appeared..

`replace(_to_be_replaced,put_instead_of)`

replaces a char/string, with the char/string specified as the first argument,

common method

`slice(start_index,end_index)`

returns the chars between the start_index and the end_index-1,

common method

`split(criteria)`

splits the strings inside the main string using a certain criteria (criteria example: “,” ” ” ect.)

common method

`substr(start_included, counter_included)`

extracts the string from start_included to counter_included. The method actually returns the char from the start_included where this argument is included in the return and the counter_included where this argument is also included in the return. Similar to slice method but slice does not include the second argument index.

`substring(start_index, end_index)`

almost completely the same as the above method but the end_index is not included it is end_index-1 which is included and between this interval the string is returned.

common method

`toLowerCase()`

changes the full string to lower case letters no matter what the letters are currently in the string that is being affected.

`toUpperCase()`

changes the full string to upper case letters no matter what the letters are currently in the string that is being affected.

`toString()`

converts the data to string so that strings methods can be applied to it.

common method

`trim()`

removes both spaces at the end and the beginning of a string

Quick reference (basic methods):
``` -charAt(index) -charCodeAt(index) -concat(params) -fromCharCode(unicode_num_integer) -indexOf(string_char) -lastIndexOf(char) -replace(to_be_replaced,put_instead_of) -slice(start_index,end_index), goes till end_index-1 -split(criteria) -substr(start_included,count) includes the char at position start_included and also the count number is included -substring(start_index,end_index) end_index not included, end_index-1 included in fetching the substring -toLowerCase() -toUpperCase() -toString() -trim() ```