Introduction to javascript data types, literal quantities, and variables

Source: Internet
Author: User

Data Type:
1. Numeric (integer int floating point floating)
2. string type (string)
3. boolean (only two values: ture fasle)

String Literal
1. Escape series:
Some symbols in javascript cannot be identified. They are correctly displayed only after escaping. For example:
\ 'Single quotes
\ "Double quotation marks
\ N linefeed
\ R carriage return
\ Backslash

Escape instance:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Document. write ("hello \ nworld ");
</Script>

Escape instance output:
Copy codeThe Code is as follows:
Hello
World (line feed between hello and world)


2. String concatenation

The String concatenation operator number is the plus sign (+). When two strings are concatenated, javascript concatenates them into a string. When a number and a string are concatenated, javascript concatenates them into a string; concatenate two numbers, and operator + becomes an addition operator.


String concatenation instance
Copy codeThe Code is as follows:
Document. write ("link" + "nan"); // concatenate two strings and output linknan
Document. write ("5" + 100); // concatenate a number and a string to output 5100
Document. write (5 + 100); // concatenate two numbers and output 105


3. typeof Operator

Used to determine the data type.
Copy codeThe Code is as follows:
Docunment. write (typeof (linknan); // linknan is a character type and outputs String


Composite data type

1. Variables

The value of a variable can be changed. Naming method: the first character must be a letter or underline, Which is case sensitive. Declare variables with var.
Copy codeThe Code is as follows:
Var num = 5; // The variable name is "num" and the value is 5.
Var num = 5; // Initialization
Var num; // not initialized


2. Constants

Constant naming usually uses uppercase letters and uses const to declare variables. After a constant initializes a value, its value remains unchanged no matter what computation is performed later.

Bugs to be aware

Note the case sensitivity when naming. Do not use reserved words or names that are too long to be easily remembered; avoid using two similar variable names; declare all variables at the beginning of the program.

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.