// 主要是ES的API和一小部分瀏覽器的API。git
// 新加入標準的API有多是瀏覽器事實上早已實現的。es6
// ECMAScript目前是每一年都會發布新版本(目前已經相對穩定,每一年都會又增長,可是變化不會像ES6那樣大),相應的版本號以下:正則表達式
// ES2015/ES6: 最大規模的一次增長,入門可看 ECMAScript 6 入門express
// ES2016/ES7:數組
// ES2017/ES8:瀏覽器
isNaN(value)app
The necessity of an isNaN
functionless
Unlike all other possible values in JavaScript, it is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN
or not(isNaN()函數的目的是爲了確認某個值是不是NaN), because both NaN == NaN
and NaN === NaN
evaluate to false
. Hence, the necessity of an isNaN
function.ide
ES6在Number上部署了isNaN()函數:函數
var isNaN = function(value) {
return Number.isNaN(Number(value)(至關於先轉化爲了數字));
}
isFinite(testValue)
The global isFinite()
function determines whether the passed value is a finite number(是一個有限的數). If needed, the parameter is first converted(若是參數不是數字,先轉化爲數字) to a number.
eval(string)
escape,encodeURI,encodeURIComponent有什麼區別?
都是用來將字符串進行轉碼,使其在全部的電腦上都能被識別。
一、若是隻是編碼字符串,不和URL有半毛錢關係,那麼用escape。
二、若是你須要編碼整個URL,而後須要使用這個URL,那麼用encodeURI。
三、當你須要編碼URL中的參數的時候,那麼encodeURIComponent是最好方法。
The encodeURIComponent()
function encodes a Uniform Resource Identifier (URI) component(處理URI中的一部分) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
encodeURI() decodeURI()
The encodeURI()
function encodes a Uniform Resource Identifier (URI)(處理整個URI) by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).
instanceof
operatorThe instanceof
operator tests whether an object has in its prototype chain the prototype
property of a constructor.
object instanceof constructor
檢測構造器函數constructor的prototype屬性是否在object的原型鏈上
typeof
The typeof
operator(typeof是一個操做符,不是函數,因此後面的()不是必須的) returns a string indicating the type of the unevaluated operand(後面的操做對象).
operand
is an expression representing the object or primitive whose type is to be returned.
typeof 判斷基本類型很準確,在判斷引用類型時不許確
in
operatorThe in
operator returns true
if the specified property is in the specified object or its prototype chain(在對象或是原型鏈上是否有相應的屬性).
The Object.prototype
property represents the Object
prototype object.
Object.getOwnPropertyNames()
The Object.getOwnPropertyNames()
method returns an array of all properties (enumerable or not) found directly upon a given object.
返回一個對象自身上面的屬性(不包括原型鏈,包括不可枚舉屬性)組成的數組,數組元素爲字符串。
The Object.keys()
method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in
loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
返回一個對象自身上面的可枚舉屬性(不包括原型鏈,不包括不可枚舉屬性)組成的數組,數組元素爲字符串。
Notes: for...in loop 遍歷自身的+原型鏈上的可枚舉屬性
The Object.getOwnPropertySymbols()
method returns an array of all symbol properties found directly upon a given object.
返回一個對象自身上面的symbol屬性(不包括原型鏈)組成的數組
The Object.create()
method creates a new object with the specified prototype object and properties.
var a = Object.create(b) // b是a的原型對象
The Object.setPrototypeOf()
method sets the prototype (i.e., the internal [[Prototype]]
property) of a specified object to another object or null
.
Object.setPrototypeOf(obj, prototype);
prototype是obj的原型對象
Polyfill
Using the older Object.prototype.__proto__ property, we can easily define Object.setPrototypeOf if it isn't available already:
// Only works in Chrome and FireFox, does not work in IE:
Object.setPrototypeOf = Object.setPrototypeOf || function(obj, proto) {
obj.__proto__ = proto;
return obj;
}
The Object.getPrototypeOf()
method returns the prototype (i.e. the value of the internal [[Prototype]]
property) of the specified object.
Object.getPrototypeOf(obj)
obj :The object whose prototype is to be returned.
Return value:The prototype of the given object. If there are no inherited properties, null is returned.
返回obj的內部的[[prptotype]],即部分瀏覽器暴露出來的_proto_屬性對象。
The Object.is()
method determines whether two values are the same value.
Object.assign(target, ...sources)
The Object.assign()
method is used to copy the values of all enumerable(可枚舉屬性,包括字符串屬性和Symbol屬性) own properties from one or more source objects to a target object. It will return the target object.
Object.getOwnPropertyDescriptor(obj, prop)
The Object.getOwnPropertyDescriptor()
method returns a property descriptor(返回一個描述符對象) for an own property (that is, one directly present on an object and not in the object's prototype chain) of a given object.
Object.getOwnPropertyDescriptor(obj) //ES8
Return: An object(返回一個對象) containing all own property descriptors of an object. Might be an empty object, if there are no properties.
Object.defineProperty(obj, prop, descriptor)
The Object.defineProperty()
method defines a new property directly on an object, or modifies an existing property on an object, and returns the object.
Object.preventExtensions(obj)
The Object.preventExtensions()
method prevents new properties from(阻止添加新的屬性,可是能夠刪除以前的) ever being added to an object (i.e. prevents future extensions to the object).
Object.seal(obj)
The Object.seal()
method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable(阻止添加新的屬性,已有屬性的configurable設爲false,即對象不可編輯). Values of present properties can still be changed as long as they are writable(可是可寫的仍可寫).
Object.freeze(obj)
The Object.freeze()
method freezes an object: that is, prevents new properties from being added to it; prevents existing properties from being removed; and prevents existing properties, or their enumerability, configurability, or writability, from being changed. The method returns the object being frozen.
被凍結的對象,屬性不可添加,不可刪除屬性,屬性的特性也不可變。也就是,被凍結的對象不可改變(immutable)
To make an object constant, recursively freeze each property(遞歸的凍結對象的屬性的屬性....) which is of type object (deep freeze).
// To do so, we use this function.
function deepFreeze(obj) {
// Retrieve the property names defined on obj
var propNames = Object.getOwnPropertyNames(obj);
// Freeze properties before freezing self
propNames.forEach(function(name) {
var prop = obj[name];
// Freeze prop if it is an object
if (typeof prop == 'object' && prop !== null)
deepFreeze(prop);
});
})
// Freeze self (no-op if already frozen)
return Object.freeze(obj);
}
obj2 = {
internal: {}
};
deepFreeze(obj2);
obj2.internal.a = 'anotherValue';
obj2.internal.a; // undefined
Object.isExtensible(obj)
Object.isFrozen(obj)
Object.isSealed(obj)
檢測obj是不是extensible/frozen/sealed,返回布爾值
Object.values(obj) // ES8
The Object.values()
method returns an array(返回一個數組) of a given object's own enumerable property values(對象自身的可枚舉屬性), in the same order as that provided by a for...in
loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
Object.entries(obj) // ES8
The Object.entries()
method returns an array of a given object's own enumerable property [key, value]
pairs(對象自身可枚舉屬性的key,val組成的數組), in the same order as that provided by a for...in
loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).
The hasOwnProperty()
method returns a boolean indicating whether the object has the specified property.
返回布爾值,對象自身是否有某屬性
The isPrototypeOf()
method checks if an object exists in another object's prototype chain.
prototypeObj.isPrototypeOf(object)
檢測prototypeObj是否在object的原型鏈上
isPrototypeOf() differs from the instanceof operator. In the expression "object instanceof AFunction", the object prototype chain is checked against AFunction.prototype, not against AFunction itself.
與instanceof區別:一個是檢測對象,一個是檢測構造函數的原型對象
The propertyIsEnumerable()
method returns a Boolean indicating whether the specified property is enumerable.
obj.propertyIsEnumerable(prop)
The toString()
method returns a string representing the object.
Return value
A string representing the object.
Description
Every object has a toString()
method that is automatically called(tostring()會自動被調用,當一個「字符串」被期待時) when the object is to be represented as a text value or when an object is referred to in a manner in which a string is expected. By default, the toString()
method is inherited by every object descended from Object
. If this method is not overridden(若是tostring方法沒有被重寫) in a custom object, toString()
returns "[object type]", where type
is the object type.
eg:判斷數據類型
Array.from(arrayLike[, mapFn[, thisArg]])
The Array.from()
method creates a new Array
instance from an array-like or iterable object(從類數組或是可遍歷的對象生成數組).
array-like objects (objects with a length property and indexed elements) or iterable objects (objects where you can get its elements, such as Map and Set).
More clearly, Array.from(obj, mapFn, thisArg) has the same result as(先後二者的效果相同) Array.from(obj).map(mapFn, thisArg), except that it does not create an intermediate array. This is especially important for certain array subclasses, like typed arrays, since the intermediate array would necessarily have values truncated to fit into the appropriate type.
Array.isArray(obj)
The Array.isArray()
determines whether the passed value is an Array(判斷是不是數組)
.
Polyfill
if (!Array.isArray) {
Array.isArray = function(arg) {
return Object.prototype.toString.call(arg) === '[object Array]';
};
}
Array.of(element0[, element1[, ...[, elementN]]])
The Array.of()
method creates a new Array
instance with a variable number of arguments, regardless of(忽略掉參數的個數和類型) number or type of the arguments.
The difference between Array.of()
and the Array
constructor is in the handling of integer arguments(與Array()構造函數的區別是處理單個數字元素時): Array.of(7)
creates an array with a single element, 7
, whereas Array(7)
creates an empty array with a length
property of 7 (Note: this implies an array of 7
empty slots, not slots with actual undefined
values).
Array.of(7); // [7]
Array.of(1, 2, 3); // [1, 2, 3]
Array(7); // [ , , , , , , ]
Array(1, 2, 3); // [1, 2, 3]
The toString()
method returns a string representing the specified array and its elements.
The Array
object overrides the toString
method of Object(重寫了Object.prototype上的toString()方法,等於.join(","))
. For Array objects, the toString
method joins the array and returns one string containing each array element separated by commas.
JavaScript calls the toString
method automatically when an array is to be represented as a text value or when an array is referred to in a string concatenation.
The unshift()
method adds one or more elements(在數組開始添加一個或是多個元素) to the beginning of an array and returns the new length of the array.
Return value
The new length
property(返回新數組的長度) of the object upon which the method was called.
Array.prototype.sort([compareFunction])
The sort()
method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points.
If compareFunction
is not supplied, elements are sorted by converting them to strings and comparing strings(若是沒有提供compareFunction函數,則將其轉化爲字符串,而後比較Unicode碼點) in Unicode code point order.
Return value
The sorted array(返回被排序過的數組).
compareFunction(a, b)的返回值小於0,則a<b;
compareFunction(a, b)的返回值大於0,則a>b;
var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])
拼接數組,返回新數組
Notes(應用場景):Every time you find yourself going from a list of values to one value ( reducing )(從一個列表裏獲取/減小到一個值) ask yourself if you could leverage the built-in Array.prototype.reduce()
function.
arr.reduce(callback, [initialValue])
callback
Function to execute on each value in the array, taking four arguments:
accumulator 累積值,不必定是累加值
The accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.)
currentValue
The current element being processed in the array.
currentIndex
The index of the current element being processed in the array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
array
The array reduce was called upon.
initialValue
Optional. Value to use as the first argument to the first call of the callback.
初始化的值,可選,若是提供,則做爲回調函數的第一個參數
eg:
[0, 1, 2, 3, 4].reduce( (accumulator, currentValue, currentIndex, array) => {
return accumulator + currentValue;
}, 10);
The slice()
method returns a shallow copy of a portion of an array into a new array object selected from begin
to end
(end
not included,不包括included). The original array will not be modified.
[1,2,3,4,5].slice(1,-1) // 返回 [2,3,4]
淺複製:淺複製指的是複製的element,而不是對象自己
返回的是一個淺複製的數組,淺複製與原數組指向的是相同內存地址。
array.splice(start, deleteCount, item1, item2, ...)
從start位置開始,刪除deleteCount個元素,並插入後面的元素
若是沒有插入元素,則返回undefined.
The splice()
method changes the contents of an array by removing existing elements and/or adding new elements.
Return value
An array containing the deleted elements(返回被刪除的數組). If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned.
Array.prototype.every(callback[, thisArg])
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].every(isBigEnough); // false
[12, 54, 18, 130, 44].every(isBigEnough); // true
都爲true,則爲true
Array.prototype.some(callback[, thisArg])
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 130, 44].some(isBigEnough); // true
[1, 4, 5].some(isBigEnough); // false
一個爲true,則爲true
Array.prototype.map(callback[, thisArg])
The map()
method creates a new array with the results of calling a provided function on every element(映射每個元素,生成新的數組) in this array.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8].map(isBigEnough); // [true,false,false]
Array.prototype.filter(callback[, thisArg])
The filter()
method creates a new array with all elements that pass the test implemented(測試函數返回true,則保留相應地元素,push進新的數組) by the provided function.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[12, 5, 8, 11 ].filter(isBigEnough); // [12, 11]
Array.prototype.forEach(callback[, thisArg])
The forEach()
method executes a provided function once for each array element(對每個元素依次執行函數).
eg:
var a = ['a', 'b', 'c'];
a.forEach(function(element) {
console.log(element);
});
// a
// b
// c
Array.prototype.find(callback[, thisArg])
The find()
method returns the value of the first element in the array that satisfies the provided testing function(依次遍歷元素,若是函數返回true,則返回元素). Otherwise undefined
is returned(不然返回undefined).
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[1, 5, 8, 11, 1, 12].find(isBigEnough); // 11(返回的不是數組,返回的是元素)
Array.prototype.findIndex(callback[, thisArg])
The findIndex()
method returns the index of the first element(返回第一個函數返回true的元素的位置) in the array that satisfies the provided testing function. Otherwise -1 is returned.
eg:
function isBigEnough(element, index, array) {
return element >= 10;
}
[1, 5, 8, 11, 1, 12].findIndex(isBigEnough); // 3 (返回的元素的位置)
The entries()
method returns a new Array Iterator
object(返回一個遍歷器對象) that contains the key/value pairs(遍歷器對象的value屬性是一個數組) for each index in the array.
The values()
method returns a new Array Iterator
object(返回一個遍歷器對象) that contains the values for each index(遍歷器對象的value就是數組的元素值) in the array.
The keys()
method returns a new Array Iterator
that contains the keys for each index(遍歷器對象的value是數組元素的index) in the array.
The fill()
method fills all the elements of an array from a start index to an end index with a static value.
Array.prototype.fill(value[, start] [, end])
把數組內的全部元素轉化爲同樣的
var numbers = [1, 2, 3]
numbers.fill(1);
// results in [1, 1, 1]
Array.prototype.indexOf(searchElement[, fromIndex])
The indexOf()
method returns the first index at which a given element can be found in the array, or -1 if it is not present.
// ES7 ES2016
Array.prototype.includes(searchElement[, fromIndex])
The includes()
method determines whether an array includes a certain element, returning true
or false
as appropriate.
包含某元素,則爲true,反之則爲false
If fromIndex
is greater than or equal to the length of the array, false
is returned.
fromIndex 默認爲0,若是是負數,則從後往前搜尋。
Array.prototype.join([separator])
The join()
method joins all elements of an array (or an array-like object) into a string.
把全部的元素拼接成字符串,seperator可選,默認值是「,」,若是數組爲空,則返回空字符串,若是隻有一個元素,則只返回一個元素組成的字符串。
數組位置換位
The length
property specifies the number of arguments(參數的個數) expected by the function.
The bind()
method creates a new function(返回一個有特定this的函數對象) that, when called, has its this
keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
The call()
method calls a function(返回的時結果,函數在特定this的狀況下執行以後的結果) with a given this
value and arguments provided individually.
The apply()
method calls a function with a given this
value, and arguments
provided as an array (or an array-like object).
str.charAt(index)
The charAt()
method returns the specified character from a string(返回字符串第index位置上的字符).
If the index
you supply is out of range, JavaScript returns an empty string.If no index is provided to .charAt(), 0 will be used as default.(index默認是0,如果index超出範圍,則返回空字符串)
str.charCodeAt(index)
index
An integer greater than or equal to 0 and less than the length of the string; if it is not a number(默認爲0), it defaults to 0.
Return value
A number representing the UTF-16 code(返回index位置上的字符串的Unicode編碼位置) unit value of the character at the given index; NaN if index is out of range(若是index在範圍以外,則返回NaN).
str.replace(regexp|substr, newSubstr|function)
str裏面如有第一個參數,則用第二個參數取代第一個參數。
The replace()
method returns a new string with some or all matches of a pattern
replaced by a replacement
. The pattern
can be a string or a RegExp
, and the replacement
can be a string or a function to be called for each match.
Return value
A new string(返回一個新的字符串,可是原來的字符串沒有變) with some or all matches of a pattern replaced by a replacement.
indexOf()
method returns the index within the calling
String
object of the first occurrence of the specified value, starting the search at
fromIndex
. Returns -1 if the value is not found.
Return value
The index of the first occurrence of the specified value; -1 if not found.
返回特定值第一次出現的位置,若是沒有,則返回-1
lastIndexOf()
method returns the index within the calling
String
object of the last occurrence of the specified value,
searching backwards from fromIndex(從後往前)
. Returns -1 if the value is not found.
search()
method executes a search for a match between a regular expression and this
String
object.
search()
. Otherwise,
indexOf()
is going to be faster.
obj
is passed, it is implicitly converted to a
RegExp
by using
new RegExp(obj)
. If you don't give any parameter and use the match() method directly, you will get an
Array
with an empty string:[""].
match()
method retrieves the matches when matching a
string against a
regular expression.
Array
containing the entire match result and any parentheses-captured matched results;
null
if there were no matches.
concat()
method combines the text of one or more strings and returns a new string.
slice()
method extracts a section of a string and returns a new string.
substring()
method returns a subset of a
string
between one index and another, or through the end of the string.
slice() works like substring() with a few different behaviors.
Syntax: string.slice(start, stop);
Syntax: string.substring(start, stop);
What they have in common:
If start equals stop: returns an empty string
If stop is omitted: extracts characters to the end of the string
If either argument is greater than the string's length, the string's length will be used instead.
Distinctions of substring():
If start > stop, then substring will swap those 2 arguments(交換兩個參數).
If either argument is negative or is NaN, it is treated as if it were 0(參數爲負數或NAN,當作0).
Distinctions of slice():
If start > stop, slice() will NOT swap the 2 arguments.
If start is negative: sets char from the end of string, exactly like substr() in Firefox. This behavior is observed in both Firefox and IE.
If stop is negative: sets stop to: (string.length – 1) – Math.abs(stop) (original value).
substr()
method returns the characters in a string beginning at the specified location through the specified number of characters.
start
Location at which to begin extracting characters. If a negative number is given(若是是負值,則從後往前), it is treated as strLength + start where strLength is the length of the string (for example, if start is -3 it is treated as strLength - 3.)
length
Optional. The number of characters to extract.
Return value
A new string containing the extracted section of the given string. If length is 0 or a negative number(若是是0或是負數,則返回新的空字符串), an empty string is returned.
split()
method splits a
String
object into an array of strings by separating the string into substrings.
separator
Optional. Specifies the character(s) to use for separating the string. The
separator
is treated as a
string or a regular expression(分隔符可選,是字符串或是正則表達式). If
separator
is
omitted or does not occur in str, the array returned contains one element consisting of the entire string. If
separator
is an empty string,
str
is converted to an array of characters
str.toLowerCase()
toLowerCase()
method returns the calling string value converted to lower case.
toLocaleLowerCase()
method returns the calling string value converted to lower case, according to any locale-specific case mappings.
str.trim()
The trim()
method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace(這裏的空白指的是全部的空白) characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
Polyfill
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}
「\uFEFF」和「\xA0」
某些軟件,在保存一個以UTF-8編碼的文件時,會在文件開始的地方插入三個不可見的字符(0xEF 0xBB 0xBF,即BOM),轉碼後是「\uFEFF」,所以咱們在讀取時須要本身去掉這些字符。
「\xA0」其實就是HTML中常見的「 」
str.padStart(targetLength [, padString]) // ES8
The padStart()
method pads the current string with another string (repeated, if needed) so that the resulting string reaches the given length. The padding is applied from the start (left) of the current string.
用padString對str進行擴充,直到最終的長度爲targetLength
Number.isNaN(value)
TheNumber.isNaN()
method determines whether the passed value is
NaN
and its type is
Number
. It is a more robust version of the original, global
isNaN()
.
Polyfill
Number.isNaN = Number.isNaN || function(value) {
// 與window.isNaN()不一樣,Number.isNaN() 須要先判斷其是不是數字
return typeof value === 'number' && isNaN(value);
}
// Or
Number.isNaN = Number.isNaN || function(value) {
return value !== value;
}
The Number.isFinite()
method determines whether the passed value is a finite number.
Polyfill
Number.isFinite = Number.isFinite || function(value) {
return typeof value === 'number' && isFinite(value);
}
new Date();
new Date(value);
new Date(dateString);
new Date(year, month[, date[, hours[, minutes[, seconds[, milliseconds]]]]]);
Date
object for the current date(若是沒有參數,則生成當前時間的對象) and time according to system settings.Date
object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.Date
object provides uniform behavior across platforms. The time value can be passed between systems to create a date that represents the same moment in time.Date
object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.Date
as a function (i.e., without the new
operator(若是直接調用構造函數,沒有用new調用,則生成表明當前時間的字符串)) will return a string representing the current date and time.Date.now()
Returns the numeric value corresponding to the current time - the number of milliseconds(當前時間的毫秒數) elapsed since 1 January 1970 00:00:00 UTC, with leap seconds ignored.
(1-31) 返回的是幾號。
(0-6)
(4 digits for 4-digit years)
(0-23)
返回從1970.1.1 00:00 (UTC時間) 到如今的毫秒數
返回當前操做系統所在時區和UTC的時差,時差是分鐘。
東八區比UTC快八個小時,因此爲-480.
Date.prototype.setDate()
Date.prototype.setFullYear()
Date.prototype.setHours()
Date.prototype.setMilliseconds()
Date.prototype.setMinutes()
Date.prototype.setMonth()
Date.prototype.setSeconds()
Date.prototype.setTime()
RegExp.prototype.exec(str)
The exec()
method executes a search for a match in a specified string. Returns a result array, or null
.
If you are executing a match simply to find true or false(若是你僅僅是判斷true或是false), use the RegExp.prototype.test()
method or the String.prototype.search()
method.
If the match succeeds, the exec()
method returns an array and updates properties of the regular expression object. The returned array has the matched text as the first item(匹配出來的數組中,第一個元素是匹配的文本,後面的元素都是「括號」裏面的), and then one item for each capturing parenthesis that matched containing the text that was captured.
If the match fails, the exec()
method returns null
.
RegExp.prototype.test(str)
The test()
method executes a search for a match between a regular expression and a specified string. Returns true
or false
.
Math
is a built-in object that has properties and methods for mathematical constants and functions. Not a function object.
Description
Unlike the other global objects, Math
is not a constructor(不像其它的全局對象,Math不是構造函數,是一個內置的對象). All properties and methods of Math
are static. You refer to the constant pi as Math.PI
and you call the sine function as Math.sin(x)
, where x
is the method's argument. Constants are defined with the full precision of real numbers in JavaScript.
Math.max()
function
returns the largest(返回最大值) of zero or more numbers.