JavaScript basic syntax

Source: Internet
Author: User

1. Data type
JavaScript data types
Basic type:
Number: Numeric
String: Strings
Boolean: Boolean type
Special types:
Null: Empty
Undefined: Not defined
Complex Type:
Array: Arrays
Object: Objects

2.String type
Represents text
A sequence of Unicode characters, numbers, punctuation marks
A pair of single or double quotation marks
Special characters need escape characters \, such as: \n,\\,\ ', \ "

3.Number type
No distinction between integral and floating-point values
All numbers are stored in 64-bit floating-point format, similar to double format
Integer:
10 binary integers consist of a sequence of numbers
16 binary data front plus 0x, octal front plus 0
Floating point number:
Use decimal points to record data, such as 3.4,5.6
Record data using an exponent, such as 4.3e23 = 4.3*10^23

3.Boolean type
Only two values: True and False
Also represents 1 and 0
True=1,false=0 in the actual operation
More for structure control statements

4. Implicit conversion of data types
JavaScript is loosely programming language
Variable does not need to specify a data type when declaring
Variable has an assignment operation to determine the data type
Different types of data are automatically converted during the calculation
Number + string: number converted to string
Number + Boolean: True converts to 1,false to 0
String + Boolean value: Boolean converted to string true or False
Boolean + Boolean: Converts a Boolean value to a number 1 or 0

5. Data type Conversion functions
Tostring
Convert to String
All data types can be converted to string types
parseint
Cast to Integer
Returns Nan (not a number) if it cannot be converted
For example parseint ("6.12") returns 6
Parsefloat
Cast to floating point number
If it cannot be converted, it returns Nan
For example parsefloat ("6.12") returns 6.12
typeof
Query value current type, return String/number/boolean/object
For example typeof ("Test" +3) = "string"
IsNaN
Determine if the value is

6. Special data types
Null
Null means "No value" or "no object" in the program
You can clear the contents of a variable by assigning a value of NULL to a variable
Undefined
A variable was declared but never assigned or the object property does not exist

7. Conditional operators
The conditional operator, also known as the "Trinocular"/"ternary" operator, has the following structure:
A Boolean expression? Expression 1: Expression 2
The value of the Boolean expression is evaluated first, and if true, the value of the entire expression is the value of expression 1
If False, the value of the entire expression is the value of expression 2

JavaScript basic syntax

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.