1.JavaScript Math (Arithmetic) object
The Math object works by performing common arithmetic tasks.
1.1 Math Object
The Math object works by performing normal arithmetic tasks.
The Math object provides a variety of arithmetic value types and functions. You do not need to define it before using this object.
Syntax for using the properties/methods of math:
var x=Math.PI; var y=math.sqrt (+);
Note: The Math object does not need to be defined before the object is used.
1.2 Calculation value
JavaScript provides 8 arithmetic values that can be accessed by the Math object:
You can refer to the following JavaScript constants using this method:
Math.EMath.PIMath.SQRT2Math.SQRT1_2Math.LN2Math.LN10Math.LOG2EMath.LOG10E
1.3 Arithmetic methods
In addition to the arithmetic values that can be accessed by the Math object, there are several functions (methods) that can be used.
The following example rounds a number by using the round method of the Math object.
document.write (Math.Round (4.7));
The following example uses the random () method of the Math object to return an arbitrary number between 0 and 1:
document.write (Math.random ());
The following example uses the floor () method and random () of the Math object to return a random number between 0 and 11
document.write (Math.floor (Math.random ()));
2.JavaScript RegExp Object
REGEXP: is a shorthand for regular expressions (regular expression).
2.1 What is REGEXP?
The regular expression describes the pattern object of the character.
When you retrieve a text, you can use a pattern to describe what you want to retrieve. REGEXP is this pattern.
The simple pattern can be a single character.
More complex patterns include more characters and can be used for parsing, format checking, substitution, and so on.
You can specify the location of the search in a string, the type of character to retrieve, and so on.
2.2 Syntax
var patt=New RegExp (pattern,modifiers); or the simpler way var patt=/pattern/modifiers;
Note: When you use constructors to create regular objects, you need a regular character escaping rule (preceded by a backslash \). For example, the following are equivalent:
var New REGEXP ("\\w+"); var re =/\w+/;
2.3REGEXP modifier
Modifiers are used to perform case-insensitive and full-text searches.
The i -modifier is used to perform a case-insensitive match.
The g -modifier is used to perform a full-text search (instead of finding the first one to stop looking, but to find all matches).
2.4test ()
The test () method searches for the value specified by the string, depending on the result and returns TRUE or false.
The following example searches for the character "E" from a string:
var patt1=New RegExp ("e");d ocument.write (patt1.test (" theBest Things ());
2.5exec ()
The EXEC () method retrieves the specified value in the string. The return value is the value that was found. If no match is found, NULL is returned.
The following example searches for the character "E" from a string:
JavaScript Math (Arithmetic) object