Standard Classes
JavaScript provides a number of classes and methods for use by programmers. A few of those items are described below:
Math Class
The Math class methods are static methods that are called from the class name (e.g. Math.sqrt()). Each method takes at least one parameter and performs the required operations on it.
- Math.sqrt(num) - returns the square root of the num
- Math.pow(base, exp) - returns base raised to the exp power
- Math.min(num1, num2, ...) - returns the smallest of the list of numbers
- Math.max(num1, num2, ...) - returns the largest of the list of numbers
- Math.round(num) - returns the rounded value of num (.5+ rounds up, under .5 rounds down)
- Math.ceil(num) - returns the next highest integer - rounds up (4.2 returns 5)
- Math.floor(num) - returns the next lowest integer - rounds down (6.8 returns 6)
- Math.abs(num) - returns the absolute value of num (-5 returns 5)
- Math.random() - returns a random value between 0 and 1.0
- Math.PI - a constant used to represent 3.1415...
Date object
The Date class methods allow access to information about the date and time. They are accessed using Date.functionName. The Date object relies on internal clock, if set wrong, the wrong information will show.
- getDate() – returns the day of the month
- getDay() – returns day of the week
- getFullYear() – returns full year
- getHours() – returns hour
- getMinutes() – returns minutes
- getMonth() – returns month as a number
- getSeconds() – returns seconds