JS variables and data types

Source: Internet
Author: User

1. Variables

-javascript is a weak type of scripting language.

-var C = 3; that is, the declaration of the variable (the variable must be preceded by a VAR declaration, a programming specification).

-Naming rules for variables

-1. The variable name must begin with a letter or an underscore _ or $.

-2. The variable name cannot exceed 255 characters in length.

-3. Spaces are not allowed in variable names.

-4. Do not apply the reserved keywords and reserved symbols in the scripting language as variable names.

-5. Variable names are case-sensitive. (JavaScript is a case-sensitive language).

-Global variables

-variables declared outside the method

-Inside the method, there are no variables declared with the VAR keyword (but to use this variable, it must be done after the method call, the method is not called, the variable is not)

-Local variables

-Inside the method, variables declared with Var

2. Data type

In-ecmascript, data types are divided into basic data types and reference data types in two categories

-Basic data type: Number,boolean,string (var a = "I am the JS Code"), Undefind,null

-number: Integers and decimals (highest precision 17 decimal places), NAN (also of number, not A), Infinity (positive infinity var a = 1/0 does not error, value is positive infinity),-infinity (negative infinity)

Note: 1. In addition to the 10 binary, it can also be represented by 8-and 16-binary literals, such as 070 for 56,0xa = 10

2. Decimal is a floating-point type, if (a + b = = 0.3)//Do not do such a test, because the floating-point value is the highest precision of 17 bits, but 0.00000000000000034

-undefind: Represents a variable declaration but is not assigned a value

-null: Represents an empty object reference. (That is, assignment is null)

-Reference type: Object type (e.g. objects, arrays, regexp,date ...)

Array: var arr = [[+]

Date: var dates = new Date ();

Null object: var obj = {};

-typeof operator: Used to determine the data type. var a = 3; alert (typeof a) returns number.

parseint ("AAAVVVC")-"error. parseint ("12AAACCC")-"12

var a = null; alert (typeof a); The return value is Object, which represents a reference to an empty object

-Values for basic types and reference types

-The base type is accessed by value, because the actual value saved in the variable can be manipulated

-The reference type is accessed by reference

3. Operators

-and Java is the same, note that there is a "= = =".

= =: the equivalent character, automatic conversion of type, automatic matching. For example, var a = 1;var B = true;if (a==b), and the result is true.

= = = Type Auto-conversion does not occur

for (var i = 0;i < 5;i++) {}

for (;;) {} is about the same as the dead loop.

    

    

JS variables and 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.