JS Getting Started tutorial two [isNaN () and Isfinite () []

Source: Internet
Author: User
Tags numeric

isNaN (): is used to check whether its arguments are non-numeric values. Hint: Yes, no. (Not a number)
document.write (isNaN (0))//return False
document.write (isNaN (5-2))//return False
document.write (isNaN ("Hello"))//return True
The isfinite (number) function checks to see if its arguments are infinity.
Returns true if number is finite. Returns False if number is NaN (non-numeric) or infinity;
2): Character:
' Re right ';
In this way JS will mistakenly think that the end of the letter after you, causing errors.
So when it comes to this, escape must be used.
We can write this:
' Re right ';
In addition: You can search the escape sequence list google.com.
Simple operation Example of a string:
var a = "Cssrain";
var B = A.charat (a.length-1);  Intercepts the last character from the string A. Output: N
var c = a.substring (0, 2); Intercepts the 1th, 2 characters from the string A. Output: CS
var d = a.indexof (' s '); Finds the position of the first S occurrence from string a. Output: 1
As can be seen from the example, the cardinality starts from 0.
var e = a.substring (a.length-1); As you can see, the 2nd parameter of substring is not written,
The default is to the end.
var f = a.substring (a.length-1, a.length);//equivalent to
3): The conversion between numbers and characters:
Digit Turn character:
var number_to_string = number + ""; Method 1: Add an empty string.
var number_to_string =string (number); Method 2: Use the string () function.
var number_to_string =number. ToString (); Method 3: Use the ToString () function.
Note: the ToString () method is converted by default in 10.
If you want to use the 8 binary conversion, you can write this: number. ToString (8);
Character Spin number:
var string_to_number = string–0; Method 1: String minus 0.
var string_to_number = number (string); Method 2: Use the number () function.
var string_to_number = parseint (string); Method 3: Use the parseint () function.
String+0 can not be used in Method 1; This can result in string concatenation, not type conversions.
The number function conversion in Method 2 is very strict.
Like what:
var a = "19cssrain86";
var b = number (a); Output Nan.
If we use Method 3.
var C = parseint (a); Output 19
You can see that parseint () automatically ignores parts that are not digital.
parseint () takes only the integer part, ignoring the fractional part.
Parsefloat () will also take the decimal part of the division.
As with ToString (), parseint is also in the system, the default is 10.
If you want to use 8, you can write this: parseint ("077", 8); Output 63 = 7 * 8 + 7
When the character begins with 0, we must specify the second parameter, or JS may be converted to 8.
4): Boolean type:
Boolean in the digital environment: true converts to 1, false to 0.
In a character environment: true converts to True and false to false.
Boolean conversions:
var X_to_boolean = Boolean (x); Method 1: Use the Boolean () function.
var x_to_boolean =!x; Method 2: Use an exclamation mark.
5): Definition of function:
Method 1: Generic definition
function Square (x) {
return x*x;
}
Method 2: Function Direct Quantity definition
var square = function (x) {return x*x;} Recommended Use
Method 3: Construct parameters
var square = new Function ("X", "Return x*x;"); Low efficiency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.