JavaScript Basics-Data types

Source: Internet
Author: User

I. Basic data types

1. Character type: denotes the type of character, example: ' AAA ', ' aaaa ', ' 123456 ', ' (null character)

2, Number type: The type of the number, example: 0,1,3.1415936, etc.

Special Number type: Infinity infinity, corresponding-infinity means infinite small number

Nan (not a number), Nan is a special numeric type that is not equal to any number, and is not equal to itself, and can only be judged by isNaN ().

3. Boolean type: A value that represents true or false, only true,false two values.

Second, composite data types

1, array: The combination of data elements, including elements and subscripts (subscript starting from 0 numbering).

The array operator is [] and can be read and assigned by [].

2, object: Object is a collection of data, data can be basic type, composite type.

Objects have properties and methods, for example: document.write () is a method operation. Document.fgcolor is a property.

III. Special Data types

1. Functions: Blocks of code that can be executed can be defined more than once.

One or more parameters can be defined, and the number of arguments can be unequal when called.

You can return a value or not return a value

  

2, NULL: null type, the type is non-basic type, non-composite type, is an empty.

3. Undefined: undefined type

Iv. Conversion of data types

1, NULL, 0,null.undefined is bool when false, the rest is true.

2, the pure number string can be converted to a number, otherwise converted to Nan, or part of the number.

3, the Boolean value can be converted to a number, true to 1, false to 0, the string is quoted.

4, NULL to 0,undefined to number when the number is Nan.

V. Direct volume

1, direct Volume: The amount of direct display in the program, including the direct volume of the string, digital direct quantity, all data types have a direct amount.

1.1. The direct amount of the string: The amount that is caused by the use of paired "or". \ is an escape character that can escape various special characters. For example \ ' means escape after ', here ' is an ordinary character not a property string start end flag.

1.2, Digital direct volume such as Var b=20, here 20 is the digital direct quantity. Digital Direct volume includes a variety of: decimal, octal, floating-point class and so on.

1.3, Boolean direct volume true,false;

1.4. The direct amount of the array, representing the direct amount of the contents of the array, example: [Ten, "AABC", true].

1.5. function Direct quantity, function variable without function name such as Var myfun= function(A, b) {a+b}, here is the direct amount of the function.

1.6, the direct volume of the object: Var obj= {"Name": "Mopheify", "Age": 20};

1.7. Special Direct quantity: Var nullobj=null is a special null direct quantity. var undefinedobj=undefined is a direct variable of undefined.

Vi. variables

1, the variable as the name implies will change the amount of storage for the data container.

1.1. Start with a letter, underscore (_), or dollar sign ($) followed by a letter, number, underscore (_), or dollar sign ($). You cannot have spaces or other punctuation.

1.2, case-sensitive, var name= "", and Var name= "" is two completely different variables.

1.3. Cannot be the same as the reserved word.

1.4. Naming rules: Pascal names all the initial letters of the word size. Example: Username,myhat

Camel name All words are capitalized except the first letter lowercase. Username,myhat

Hungarian name: Same as Pascal, but add a lowercase type abbreviation before the variable to indicate the data type.

  

2, the variable is untyped or weak type: example var x=0;x= "string", that is, the type of x varies with the value.

  

3, variables have scope: Global variables, local variables.

3.1. Variable variables defined with VAR are scoped to the definition and do not define the variables that are used directly in the global context.

3.2, variables note: a), as far as possible to define and reuse. b), you can assign a value to an undefined variable to be manipulated (at which time the variable is a global variable)

  

4, variables everywhere definition, and the definition of the scope of the parallel is valid, but before the definition of the use of a value of undefined is not null;

5, the variable can be defined many times the example var myname= ' name1 '; var myname=5; Each definition is a valid definition.

      

Seven, constant

  

1. Use const modifier to define the quantity as a constant example: const myname= "mopheify";

2, the value of the constant definition will not change. If the assignment is not valid for the above myname= "NewName", the value is still mopheify.

3. Constants cannot be defined repeatedly

4, the variable name can not be repeated with the constant name or error.

JavaScript Basics-Data types

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.