JavaScript determines if a string can be converted to a number

Source: Internet
Author: User

Determine if a string can be converted to a number

We often use the parseint function.

However, the scope of the function is very small.

Generally, the following are similar

var mystr = "123hello";

Using parseint or isNaN (MYSTR) does not determine whether the entire string is a number.

You need to use regular expressions to do this at this time.

var pattern =/^[0-9]/;

Pattern.test (MYSTR);

static variables

One variable is common to each case object. Operate at the level of the class, not at the level of the instance.

The creation of the private static variable can be created by the way of closure;

The creation of a public static variable is much simpler, just as the property of the constructor object.

Whether it is a private static method: see if it needs to access any instance data. If it is not needed, it is more efficient to design it as a static method.

Portal

JavaScript determines if a string can be converted to a number

Related Article

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.