About JS (vi) How to tell if a variable is an array type? How do I tell if a variable is number type? (There are more than one)

Source: Internet
Author: User

Number

This type is used to represent integers and floating-point values. The typeof operator can determine the type of number.

There is also a special value, NaN (non-numeric not a number), which is used to denote a case where an operand that would have returned a numeric value does not return a value (so that no error is thrown). For example, in other programming languages, dividing any number by 0 will result in an error, thereby stopping code execution. In JavaScript, however, any number divided by 0 returns Nan, so it does not affect the execution of other code.

The Nan itself has two unusual features. First, any operation involving Nan, such as NAN/10, will return Nan, a feature that can cause problems in a multi-step calculation. Second,nan is not equal to any value, including the Nan itself . For example, the following code returns false.

alert(NaN == NaN);    //false

Array

The instanceof operator, which has something to do with object-oriented in JavaScript, is to understand this by first understanding the object-oriented JavaScript. Because this operator is the prototype object that detects whether the prototype chain of the object is pointing to the constructor.

var arr = [1,2,3,1];
Alert (arr instanceof Array); True

 

About JS (vi) How to tell if a variable is an array type? How do I tell if a variable is number type? (There are more than one)

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.