JavaScript converts data types and javascript converts data types.

Source: Internet
Author: User
Tags array to string

JavaScript converts data types and javascript converts data types.

All languages have the ability to convert data types, and javascript is no exception. It also provides developers with a large number of type conversion access methods. This article will share with you how js achieves mutual conversion of data types, the details are as follows:

String Conversion number var a = '1'; console. log (+ a); console. log (a ++); console. log (-a + 3); console. log (parseInt (a); console. log (parseFloat (a); console. log (Number (a); Numeric conversion String var a = 1; a + ''String (a);. toFixed ();. toLocaleString ();. toPrecision ();. toString (); array to string var arr = [1, 2, 3]; arr. toString (); arr + ""; array to numeric, only one digit, otherwise NaNvar arr = [1]; ++ arr; + arr; arr --; arr-0arr.toString ()-0

The data obtained by js is of the string type by default. If you perform a numerical operation, you must use parseInt to convert the data to a numerical value.

Html code:

Copy codeThe Code is as follows:
<Div id = "archive">
<Input type = "hidden" name = "page" value = "1"/>
</Div>

Js Code:

$ ("# Archive "). bind ('click', function () {var page = $ ("input [name = 'page']"). val (); // calculate the value using parseInt $ ("input [name = 'page']"). val (parseInt (page) + 1 );});

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • Javascript data type conversion (parseInt, parseFloat)
  • Js data type conversion summary notes
  • Use parseInt for data type conversion during js numeric calculation (jquery)
  • Basic Javascript tutorial-data type conversion
  • JavaScript data type and conversion
  • Summary of data type conversion methods in JavaScript
  • A Brief Introduction to implicit conversions of JavaScript Data Types

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.