JavaScript Learning Notes data types and variables

Source: Internet
Author: User

The three most basic data types in javascript: numeric, Text, Boolean.

Numeric types are divided into integers and floating-point numbers.

Text type is a character or string, placed in double quotation marks "" or single quotation mark "can be, if the string contains quotation marks, you can use the escape character, \ ' \", the other common escape characters: \ \ backslash, \ n line break, \ r carriage, \ t tab tab,\b backspace character, \f page break, \ XNN nn is a hexadecimal number that represents one character in the Latin-1 character set.

The Boolean type is divided into true and false.

The basic operators in JavaScript, including the self-increment decrement operators, are similar to C.

If you want to concatenate strings, use the + sign directly, for example:

var constring= "Hello" + "" + "world";

If you concatenate values and strings with +, JavaScript automatically converts the numeric values into strings.

A function that can convert a string to a numeric value:

parseint () and parsefloat ()

The two functions parse whether each character of the string is a valid number, and if so, return the corresponding value, otherwise stop the conversion and return the previously converted value.

For example: parseint ("123abc"), the statement returns 123, and stops when the letter A is resolved.

If you convert a string that does not contain any numbers, you get the result Nan, which means not a number.

There is a function isNaN () that checks whether a value is Nan and returns True and false.

Definition of the array:

 var  myarray = new   Array ();  var   Myarray;myarray  = new   Array ();  var  myarray = new  Array (6); var  myarray = new  Array ("Hello", 345, " Paul ", 1234 var  myarray = new   Array (); myarray[ 0] = "Hello" ;myarray[ 1 ] = 345;myarray[ 2] = "Paul" ;myarray[ 3] = 1234; 

To create a multidimensional array, declare the elements of one array again as an array.

JavaScript Learning Notes data types and variables

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.