Types of JavaScript
Like the java\c language, the basic type contains (numbers, objects, functions, Booleans, strings), whereas in JS, because of the particularity of null and undefined, the function is also the particularity of the object, so JS data type contains:
Number, String, Boolean, symbol (symbols, new version sixth), Object "Function, Array, Date, RegExp, Math", Null, Undefined
about the number object for JavaScript
JS numbers do not distinguish between integers and floating point numbers, all of which are represented by floating-point number, especially in operations
01 + 0.2 = 0.3000000000000004
Note: The reason is that the IEEE 754 standard is used to calculate, and not only JS is so, where this law is so.
NaN "non-numeric not a number"
Used to indicate that an operand that would have returned a numeric value did not return a numeric value (guaranteed program is not abnormal), js, 0/0 = NaN
Nan = = = Nan//false nan is not equal to any number including itself. NAN/10//nan nan with any number of operations returns Nan
Methods for numeric conversions:
Number (), parseint (), Parsefloat () method:
Number () Method:
Number (false); 0Number (TRUE); 1Number ("011"); 11Number ("); 0 If NULL, the return value is 0Number (undefined), and//nan if it is undefined, returns NaN
Pareseint () Method:
parseint (' 456 ', 10); 456parseInt ("Hello", 10); NaN
The parseint () method, in the process of converting numeric values, is more concerned with whether or not to conform to the numeric pattern, he ignores the space before the character, finds the first non-whitespace character, and returns Nan if it is not a character or minus sign.
Parsefloat () Method:
parsefloat (' 22.34.5 '); 22.35parseFloat (' 1234blued '); 1234parseFloat (' 0908.5 '); 908.5
The Parsefloat () method is consistent with the parseint (), the difference being that parsefloat () only parses decimal integers, so there is no back base
and the function attempts to parse the characters in the string one after the other, until a character that cannot be parsed into a number is encountered, and then returns a number that consists of all numeric characters before the character. parseInt()
parseFloat()
Use the operator "+" to convert a string to a number, as long as the string contains a character that cannot be parsed into a number, NaN
the string is converted to
string Object about JavaScript
A string in JavaScript is a series of Unicode characters . More precisely, they are a sequence of UTF-16 encoding units, each of which is represented by a 16-bit binary number. Each Unicode character is represented by one or two encoding units.
var text = ' Hello '; Console.log (text.length); 5
The Length property in the string indicates the number of characters in the string
Built-in methods for string objects:
Method |
Description |
CharAt () |
Returns the character at the established position |
charCodeAt () |
Returns the Unicode encoding of the character at the established position |
Concat () |
Connection string |
IndexOf () |
Retrieves the string position, where it can be set to start retrieving, not found return-1, case sensitive |
LastIndexOf () |
Consistent with indexof (), just starting with the last one. |
ToString () |
return string |
Replace () |
Used to replace some characters with some other character var str= "Visit microsoft!" ; document.write (Str.replace (/microsoft/, "W3school")) |
Split () |
Split into a string array |
Match () |
Retrieves the specified value within a string, or finds a match for one or more regular expressions |
Http://www.w3school.com.cn/jsref/jsref_obj_string.asp
Other methods refer to the links above
Revisit the basics of JavaScript (i)