Date Object
The Date object is used to work with dates and times.
Date objects are created with new Date().
There are four ways of instantiating a date:
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
var d = new Date();
var d = new Date(milliseconds);
var d = new Date(dateString);
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
Date Object Properties
| Property | Description |
|---|---|
| constructor | Returns the function that created the Date object's prototype |
| prototype | Allows you to add properties and methods to an object |
Date Object Methods
| Method | Description |
|---|---|
| getDate() | Returns the day of the month (from 1-31) |
| getDay() | Returns the day of the week (from 0-6) |
| getFullYear() | Returns the year |
| getHours() | Returns the hour (from 0-23) |
| getMilliseconds() | Returns the milliseconds (from 0-999) |
===============================
Array Object
The Array object is used to store multiple values in a single variable:
var cars = ["Saab", "Volvo", "BMW"];
Array indexes are zero-based: The first element in the array is 0, the second is 1, and so on.
Array Properties
| Property | Description |
|---|---|
| constructor | Returns the function that created the Array object's prototype |
| length | Sets or returns the number of elements in an array |
| prototype | Allows you to add properties and methods to an Array object |
Array Methods
| Method | Description |
|---|---|
| concat() | Joins two or more arrays, and returns a copy of the joined arrays |
| copyWithin() | Copies array elements within the array, to and from specified positions |
| every() | Checks if every element in an array pass a test |
| fill() | Fill the elements in an array with a static value |
| filter() | Creates a new array with every element in an array that pass a test |
| find() | Returns the value of the first element in an array that pass a test |
===============================
JavaScript Booleans
JavaScript booleans can have one of two values: true or false.
The Boolean() Function
You can use the Boolean() function to find out if an expression is true:
Example
Boolean(10 > 9) // returns true
Or even easier:
Example
(10 > 9) // also returns true10 > 9 // also returns true
Boolean Properties
| Property | Description |
|---|---|
| constructor | Returns the function that created JavaScript's Boolean prototype |
| prototype | Allows you to add properties and methods to the Boolean prototype |
Boolean Methods
| Method | Description |
|---|---|
| toString() | Converts a boolean value to a string, and returns the result |
| valueOf() | Returns the primitive value of a boolean |
========================================================================
Math Object
The Math object allows you to perform mathematical tasks.
Math is not a constructor. All properties/methods of Math can be called by using Math as an object, without creating it.
Syntax
var x = Math.PI; // Returns PIvar y = Math.sqrt(16); // Returns the square root of 16
Math Object Properties
| Property | Description |
|---|---|
| E | Returns Euler's number (approx. 2.718) |
| LN2 | Returns the natural logarithm of 2 (approx. 0.693) |
| LN10 | Returns the natural logarithm of 10 (approx. 2.302) |
| LOG2E | Returns the base-2 logarithm of E (approx. 1.442) |
| LOG10E | Returns the base-10 logarithm of E (approx. 0.434) |
| PI | Returns PI (approx. 3.14) |
| SQRT1_2 | Returns the square root of 1/2 (approx. 0.707) |
| SQRT2 | Returns the square root of 2 (approx. 1.414) |
Math Object Methods
| Method | Description |
|---|---|
| abs(x) | Returns the absolute value of x |
| acos(x) | Returns the arccosine of x, in radians |
| asin(x) | Returns the arcsine of x, in radians |
| atan(x) | Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians |
| atan2(y, x) | Returns the arctangent of the quotient of its arguments |
| ceil(x) | Returns x, rounded upwards to the nearest integer |
No comments:
Post a Comment