java script basik cheat sheeet

Solutions on MaxInterview for java script basik cheat sheeet by the best coders in the world

showing results for - "java script basik cheat sheeet"
Rodrigo
12 Sep 2016
1var abc = "abcdefghijklmnopqrstuvwxyz";
2var esc = 'I don\'t \n know';   // \n new line
3var len = abc.length;           // string length
4abc.indexOf("lmno");            // find substring, -1 if doesn't contain 
5abc.lastIndexOf("lmno");        // last occurance
6abc.slice(3, 6);                // cuts out "def", negative values count from behind
7abc.replace("abc","123");       // find and replace, takes regular expressions
8abc.toUpperCase();              // convert to upper case
9abc.toLowerCase();              // convert to lower case
10abc.concat(" ", str2);          // abc + " " + str2
11abc.charAt(2);                  // character at index: "c"
12abc[2];                         // unsafe, abc[2] = "C" doesn't work
13abc.charCodeAt(2);              // character code at index: "c" -> 99
14abc.split(",");                 // splitting a string on commas gives an array
15abc.split("");                  // splitting on characters
16128.toString(16);               // number to hex(16), octal (8) or binary (2)
17
Isaias
06 Feb 2018
1var pi = 3.141;
2pi.toFixed(0);          // returns 3
3pi.toFixed(2);          // returns 3.14 - for working with money
4pi.toPrecision(2)       // returns 3.1
5pi.valueOf();           // returns number
6Number(true);           // converts to number
7Number(new Date())      // number of milliseconds since 1970
8parseInt("3 months");   // returns the first number: 3
9parseFloat("3.5 days"); // returns 3.5
10Number.MAX_VALUE        // largest possible JS number
11Number.MIN_VALUE        // smallest possible JS number
12Number.NEGATIVE_INFINITY// -Infinity
13Number.POSITIVE_INFINITY// Infinity
14
Julián
18 Oct 2018
1var pi = Math.PI;       // 3.141592653589793
2Math.round(4.4);        // = 4 - rounded
3Math.round(4.5);        // = 5
4Math.pow(2,8);          // = 256 - 2 to the power of 8
5Math.sqrt(49);          // = 7 - square root 
6Math.abs(-3.14);        // = 3.14 - absolute, positive value
7Math.ceil(3.14);        // = 4 - rounded up
8Math.floor(3.99);       // = 3 - rounded down
9Math.sin(0);            // = 0 - sine
10Math.cos(Math.PI);      // OTHERS: tan,atan,asin,acos,
11Math.min(0, 3, -2, 2);  // = -2 - the lowest value
12Math.max(0, 3, -2, 2);  // = 3 - the highest value
13Math.log(1);            // = 0 natural logarithm 
14Math.exp(1);            // = 2.7182pow(E,x)
15Math.random();          // random number between 0 and 1
16Math.floor(Math.random() * 5) + 1;  // random integer, from 1 to 5
17