JavaScript data type, literal volume, Variable Introduction _ Basics

Source: Internet
Author: User
Tags constant
Data type:
1. Numeric type (integer int floating-point type floating)
2. String type
3. Boolean (Only two values: Ture fasle)

literal number of strings
1. Escape series:
Some symbols in JavaScript are not recognizable, and are only shown correctly after escaping. Such as:
\ ' Single quotes
\ "Double Quotes
\ n Line Feed
\ r return character
\ reverse Slash

Escape instance:
Copy Code code as follows:

<script type= "Text/javascript" >
document.write ("Hello\nworld");
</script>

Escape Instance output:
Copy Code code as follows:

Hello
World (Hello and World Change)


2. String concatenation

string concatenation operation symbols are plus (+), two string concatenation, JavaScript will stitch them into a string, when a number and a string concatenation, JavaScript will stitch them into a string, two number concatenation, operator + will become an addition operator.


string Concatenation instance
Copy Code code as follows:

document.write ("link" + "Nan"); Two string concatenation, output Linknan
document.write ("5" + 100); A number and a string concatenation, output 5100
document.write (5 + 100); Two digital stitching, output 105


3.typeof operator

Used to determine the data type.
Copy Code code as follows:

Docunment.write (typeof (Linknan)); Linknan is a character type, output string


Composite data Types

1. Variable

The value of a variable can be changed. Naming: The first character must be a letter or underscore, which is case-sensitive. Declare a variable with var.
Copy Code code as follows:

var num = 5; Variable name is "num" with a value of 5
var num = 5; Class
var num; Not initialized


2. Constant

Constant naming usually uses uppercase letters, declaring variables with const, and after constant initialization, the values are invariant regardless of the subsequent operation.

Bugs to be aware of

Note that the name should be case-sensitive, do not use reserved words or too long not easy to remember naming, avoid using two similar variable names, and declare all variables at the beginning of the program.

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.