Chapter III JavaScript data types

Source: Internet
Author: User

Table of Contents: First, some features and conventions of JavaScript ii. basic data type three, complex data type four, basic data type conversion five, typeof () function

First, some features and conventions of javascript:

1. JavaScript is case-sensitive.

2, variables, functions, properties, parameters the first character must be a letter, an underscore (_), or a dollar sign ($). Other characters can be letters, underscores, numbers, or dollar signs .

3. JavaScript identifiers are in Hump case Format , that is, the first letter lowercase, the first letter of each word is capitalized, such as: JavaScript.

4, Add "use strict" at the top of the code to enable strict mode , if it is added in the first bar inside a function, then only this function enables strict mode.

5, the statement with; end, if not added, the interpreter will automatically judge and add;

6, {} means "block".

7, keywords and reserved words can not be used for identifiers, specifically what Google Bar.

8, var for variable definition, in the function does not add VAR to the variable definition, the variable is a global variable .

Second, the basic data type:

JavaScript has 5 basic data types of basic data types:Undefined,Null,Boolean,number,String

Undefined: There is only one value, which is Undefined, represents an uninitialized variable.

Null: There is only one value, which is null, which represents a null pointer object.

Boolean: There are two values, true, false, respectively.

Number : contains integers and floating-point numbers.

String : type. a sequence of characters consisting of 0 or more 16-bit Unicode characters.

Three, complex data types:

JavaScript has 1 kinds of complex data types:Object.

An object is actually a collection of data and functions, and his method is to "generate" an instance of it by using the new object. Detail later.

Iv. Basic Data type conversions:

Convert to undefined type: No function allows a variable to be converted to undefined type.

Convert to NULL type: There is no function to convert a variable to a null type.

Convert to Boolean type: All base types can be converted to Boolean, undefined and null to False, "" (empty string) converted to false,0 and Nan to false. All others are converted to true.

Convert to Number type: There are three functions, number (), Paretint (), and parsefloat (), respectively. Number () function: The null conversion returns Nan to 0,undefined, the empty string to 0, and the object calls the ValueOf () and ToString () methods, respectively.

Convert to String type: Use a variable or literal or the ToString () method of the object.

The ToString method involves the understanding of objects and prototypes, which can be understood later, and it is now known that this method can be converted to a string type.

<script>alert ("123". toString ()); </script>
V. typeof () function:

typeof returns the target type with the return value:

    • Undefined
    • Object
    • Boolean
    • Number
    • String
<script>functionsay () {;}varNUM1 =NewNumber (123);varNUM2 = 123; alert (num1.tostring ()); //123Alert (num2.tostring ());//123AlerttypeofNUM1);//Object, because it's new .AlerttypeofNUM2);// NumberAlerttypeofSay);//function</script>

Basic data types

Chapter III JavaScript data types

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.