Home > front end >  JavaScript built-in objects
JavaScript built-in objects

Time:09-21

What is a built-in objects
1. The built-in objects
- by ES standards defined in the object, can be used in any ES the implementation of the
For example: Math String Number Boolean Function Object...

1. The Date object (built-in objects)
- use the Date in the JS object to represent a time
Create a Date object
If the time use the constructor creates a Date object, will be encapsulated in the current code execution time
For example:
Var d=new Date ();
The console. The log (d);
Create a specified time object
Need in the constructor is passed a time string as a parameter
For example:
Var date2=new Date (" 2020-03-23 12:34:12 ");
The console. The log (date2);
GetDate () - gets the current date object days
For example:

Returns:

GetDay () - gets the current date of the week
- will return a value of 0 ~ 6
0 said Sunday
1
on Monday.
6 said Saturday
For example:

2. The Month object (built-in objects)
1. GetMonth () - gets the current month of the date object
- will return a value of 0 ~ 11

0 JanuaryFebruary 1
.
December 11 said
For example:

Returns:
April said

2. Math. Abs (x) - returns the absolute value of a number
3. Math. Sin (x) - returns the sine of a number
4. Math. Ceil () - can be up to a number of integer, decimal places as long as there is value is automatically into 1
5. Math. Floor () - can be carried out on a number of downward integer, decimal part will be down
6. Math. Round () - a number can be rounded integer
7. Math. The random ()
- can be used to generate a random number between 0 and 1
Math. The random ()
- can be used to generate a random number between 0 and 10 (integer)
Math. Round (Math. The random () * 10)
- can be used to generate a random number between 0 and X (integer)
Math. Round (Math. The random () * X)
- can be used to generate a random number between 1-10 (integer)
Math. Round (Math. The random () * 9) + 1
- can be used to generate a random number between 1 - X (integer)
Math. Round (Math. The random () * (X - 1)) + 1
- can be used to generate random Numbers between a Y - X (integer)
  • Related