Basic reference type
Date
- Create a Date instance without a given time, and the created object will save the current Date and time.
- To create a Date object based on another time, you must pass in its millisecond time representation
- Date.parse()
- Month / day / year (May 21 / 2022)
- May 21, 2022
- Day of the week month name day year hour: minute: second time zone (Tue May 23 2022 00:00:00 GMT-0700)
- YYYY-MM-DDTHH:mm:ss.sssZ (2019-05-23T00:00:00 is only applicable to ES5 compatible implementations)
- Date. UTC (year, month, day, hour, minute, second): returns the millisecond representation of the date
- Date.parse()
Inherited method
Date formatting method
Date / time component method
RegExp
Original value wrapper type
Boolean
- Boolean will override the valueOf() method and return the original value true or false. The toString() method is also overridden when called
let falseObj = new Boolean(false); let result = falseObj && true; // All objects are converted to true in bool expressions console.log(result); // true let falseVal = false; result = falseVal && true; console.log(result); // false
Number
- Overridden valueOF() toLocalString() toString()
- toFixed() 0~20 decimal places
- Scientific counting method: toExponential()
- Return the most reasonable output: toPrecision()
- Is isInteger() an integer
String
Common methods:
- normalize() method
- String operation method
- slice()
- substr()
- substring()
- The first parameter represents the start position of the string, and the second parameter represents the end position
- For substr(), the second parameter represents the number of sub characters intercepted
- String position method
- indexOf(str, idx)
- lastIndexOf(str, idx)
- Search the incoming string in the string and return the position. If it is not found, return - 1
- indexOf find from scratch
- lastIndexOf starts at the end
- The second parameter means to search from the specified location
- String containing method
- startsWith(str): whether to start with str
- endWith(str): whether to end with str
- includes(str): whether to include str
- Searches the incoming string and returns a bool value
- trim() method: create a copy of the string, delete all the spaces before and after, and then return the result
- repeat(times) method: returns the result after splicing the string times
- padStart(len, str) and padEnd(len, str) methods
- Concatenate the string with the specified str and the string with the length of len
- padStart is populated at the beginning
- padEnd is filled at the end
- String iterator and Deconstruction
let message = 'abc'; let stringIterator = message[Symbol.iterator](); console.log(stringIterator.next()); // {value: 'a', done: false} for (const c of message) console.log(c); // a b c console.log([...message]); // ['a', 'b', 'c']
- String case conversion
- toLowerCase()
- toLocaleLowerCase()
- toUpperCase()
- toLocaleUpperCase()
- Local: for region specific implementation, if you don't know what language the code involves, finally use local
- String template method
- match(): essentially the same as the exec() method of RegExp object, it accepts a parameter (regular expression, RegExp object)
- search(): always return the first matching position, and the rest are the same as match
- replace(): replace
- split(): splits the string into an array based on the passed in delimiter
- localCompare() method: the locale of the implementation determines how this method compares strings
- HTML method
Singleton built-in object
Global
/** * encodeURI() * encodeURIComponent() * * decodeURI() Decode only characters encoded by encordURI() * decodeURIComponent() Decodes all characters encoded by encodeURIComponent() */ let url = 'http:// www.azoux.com/azou domy.js' console.log(encodeURI(url)); // http://%20www.azoux.com/azou%20domy.js console.log(encodeURIComponent(url)); // http%3A%2F%2F%20www.azoux.com%2Fazou%20domy.js /** * eval()Method: this method is a complete ECAMScript interpreter, which accepts a parameter, that is, a JavaScript string to be executed * When the interpreter finds Eval, it inserts the code in the eval into that location * The code called through eval belongs to the execution context of the call */ eval('console.log("azoux");'); // Equivalent to console log("azoux"); /** * Global Object properties * There is a table, basically some constructors and special values */ /** * window object * The browser implements the window object as a proxy for the Global object * Another way to get Global objects */ let global = function () { return this; }(); console.log(global); // window
Math
/** * Math Object attribute: specific table lookup */ /** * min()And max() methods * Used to determine the maximum and minimum values of a set of values */ console.log(Math.min(...[1, 2, 3, 4, 5, 6])); // 1 console.log(Math.max(...[1, 2, 3, 4, 5, 6])); // 6 /** * Rounding method * Math.ceil(): Always round up to the nearest integer * Math.floor(): Always round down to the nearest integer * Math.round(): rounding * Math.fround(): Returns the single precision (32-bit) representation of the closest value */ /** * random()Method: randomly return decimals between 0 and 1 */ /** * Other methods: look up the table */