First, the number of the wording
3.14 2345.789 . 333333333333333333 6.02e23 // 6.02x10 1.4738223E-32 // 1.4738223x10
Ii. usage of the Math object
Math.pow (2,53)//= 9007199254740992:2 to the PowerMath.Round (. 6)//= = 1.0:round to the nearest integerMath.ceil (. 6)//= = 1.0:round up to an integerMath.floor (. 6)//= = 0.0:round down to an integerMath.Abs (-5)//= = 5:absolute valueMath.max (x, Y, z)//Return the largest argumentMath.min (x, Y, z)//Return the smallest argumentMath.random ()//pseudo-random number x where 0 <= x < 1.0Math.PI//π: Circumference of a circle/diameterMath.e//e:the base of the natural logarithmMATH.SQRT (3)//The square root of 3Math.pow (3, 1/3)//The cube root of 3Math.sin (0)//trigonometry:also Math.Cos, Math.atan, etc. Math.log (10)//Natural logarithm of tenMath.log (+)/MATH.LN10//Base logarithm of 100Math.log (/MATH.LN2//Base 2 logarithm of 512Math.exp (3)//MATH.E Cubed/* Why ask Hovertree.com * *
Iii. numerical calculation of special results
Nan is not A number
Infinity//A read/write variable initialized to Infinity. Number.POSITIVE_INFINITY//same value, read-only. 1/0//This is also the same value. Number.MAX_VALUE+ 1//This also evaluates to Infinity. Number.negative_infinity//These expressions is negative infinity. -Infinity-1/0-number.max_value-1NaN//A read/write variable initialized to NaN. Number.NaN//A Read-only Property holding the same value. 0/0//evaluates to NaN. Number.min_value/2//Underflow:evaluates to 0-NUMBER.MIN_VALUE/2//Negative Zero-1/infinity//Also negative 0-0/*how to ask Hovertree.com*/
The Not-a-number value has a unusual feature in javascript:it does not compare equal to any other value, including Itse Lf.
This means so you can ' t write x = = Nan To determine whether the value of a variable x is NaN. Instead, you should write X! = x.
That expression would be true if, and only if, X is NaN. The function IsNaN () is similar.
It returns True if its argument is NaN, or if the argument is a non-numeric the value such as a string or an object.
The related function Isfinite () returns True if its argument are a number other than NaN, Infinity, or-infinity.
The negative zero value is also somewhat unusual. It compares equal (even using Java-script ' s strict equality test) to positive zero, which means that the the both values are AL Most indistinguishable, except when used as a divisor:
var zero = 0; // Regular Zero var negz =-0; // Negative Zero Zero = = Negz // = True:zero and negative zero is equal1/zero = = = 1/negz = false:infinity and-infinity is not equal // why ask Hovertree.com
Iv. errors generated by decimal decimals
The goods have a good support for the accuracy of the binary number, not in decimal.
The
JavaScript numbers has plenty of precision and can approximate 0.1 very closely. but the fact, this number cannot is represented exactly can leads to problems. Consider this Code:
var x =. 3-. 2; // thirty cents minus cents var y =. 2-. 1; // twenty cents minus cents x = = y // = false:the the same! x = =. 1 // = = false:. 3-.2 is not equal to . 1y = =. 1 //
//
He asked Hovertree.com
Fortunately, this problem only occurs when the value is compared.
V. Date Object
varthen =NewDate (2010, 0, 1);//The 1st day of the 1st month ofvarlater =NewDate (2010, 0, 1,//same day, at 5:10:30pm, local time17, 10, 30); varnow =NewDate ();//The current date and timevarelapsed = Now-then;//Date subtraction:interval in millisecondsLater.getfullyear ()// +Later.getmonth ()//= 0:zero-based monthsLater.getdate ()//= 1:one-based daysLater.getday ()//= 5:day of week. 0 is Sunday 5 is Friday. Later.gethours ()//= = 17:5pm, local timeLater.getutchours ()//hours in UTC time, depends on timezonelater.tostring ()Later.tostring ()//= "Fri Jan 17:10:30 GMT-0800 (PST)"Later.toutcstring ()//= "Sat, Jan 01:10:30 GMT"Later.tolocaledatestring ()//= "01/01/2010"Later.tolocaletimestring ()//= "05:10:30 PM"Later.toisostring ()//= "2010-01-02t01:10:30.000z"; ES5 only//how to ask Hovertree.com
Six, String Object
1. About back slashes
"Two\nlines" // A String representing 2 lines written on one line "one\ //a One-lin E string written on 3 lines. ECMAScript 5 only. long\ Line " // How to ask Hovertree.com
The backslash can appear as an escape character in JS, for example: ' You\ ' re right, it can\ ' t is a quote '. A backslash followed by a specific letter will have a special meaning, such as \ n is a newline character, the following example:
The NUL character (\u0000)
\b Backspace (\u0008)
\ t Horizontal tab (\U0009)
\ Newline (\u000a)
\v Vertical tab (\U000B)
\f Form Feed (\u000c)
\ r Carriage return (\u000d)
\ "Double quote (\u0022)
\ ' apostrophe or single quote (\u0027)
\ backslash (\u005c)
\x xx The Latin-1 character specified by the and hexadecimal digits xx
\u xxxx The Unicode character specified by the four hexadecimal digits XXXX
In addition to the preceding form, the backslash is ignored after the other characters are preceded by a backslash, for example: \ #就如同 #
Some common methods of 2.String objects (using UTF-16 encoding)
vars = "Hello, world"//Start with some text. S.charat (0)//= "H": the first character. S.charat (s.length-1)//= "D": the last character. S.substring (1,4)//= "ell": the 2nd, 3rd and 4th characters. S.slice (1,4)//= "ell": Same thingS.slice (-3)//= "Rld": last 3 charactersS.indexof ("L")//= 2:position of First letter L. S.lastindexof ("L")//= 10:position of last letter L. S.indexof ("L", 3)//= 3:position of First "L" at or after 3S.split (",")//= = ["Hello", "World"] split into substringsS.replace ("H", "H")//= "Hello, world": Replaces all instancesS.touppercase ()//= "HELLO, World"//how to ask Hovertree.com
Data of type string can be treated as a read-only array, and we can access the independent 16-bit characters, for example:
s = "Hello, world"; s[0] // = "h" s[s.length-1] // = "D" // How to ask Hovertree.com
The Guide to JavaScript ~chapter 3 of learning notes. Type, Values, and Variables
Recommendation: http://www.cnblogs.com/roucheng/p/texiao.html
JavaScript authoritative Guide