Date object, array object, Boolean object, math object

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(yearmonthdayhoursminutessecondsmilliseconds);

Date Object Properties

PropertyDescription
constructorReturns the function that created the Date object's prototype
prototypeAllows you to add properties and methods to an object

Date Object Methods

MethodDescription
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

PropertyDescription
constructorReturns the function that created the Array object's prototype
lengthSets or returns the number of elements in an array
prototypeAllows you to add properties and methods to an Array object

Array Methods

MethodDescription
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
Try it Yourself »
Or even easier:

Example

(10 > 9)              // also returns true10 > 9                // also returns true
Try it Yourself »


Boolean Properties

PropertyDescription
constructorReturns the function that created JavaScript's Boolean prototype
prototypeAllows you to add properties and methods to the Boolean prototype

Boolean Methods

MethodDescription
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

PropertyDescription
EReturns Euler's number (approx. 2.718)
LN2Returns the natural logarithm of 2 (approx. 0.693)
LN10Returns the natural logarithm of 10 (approx. 2.302)
LOG2EReturns the base-2 logarithm of E (approx. 1.442)
LOG10EReturns the base-10 logarithm of E (approx. 0.434)
PIReturns PI (approx. 3.14)
SQRT1_2Returns the square root of 1/2 (approx. 0.707)
SQRT2Returns the square root of 2 (approx. 1.414)

Math Object Methods

MethodDescription
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