Basic JavaScript data type Parsing

Source: Internet
Author: User

This article briefly introduces the JavaScript data type. Similar to other languages, the JavaScript script language has its own basic data types, expressions, arithmetic operators, and the basic framework structure of the program.

JavaScript Data Type

Like other languages, the JavaScript scripting language has its own basic data types, expressions, arithmetic operators, and the basic framework structure of the program. JavaScript provides four basic data types for processing numbers and text. While variables provide places where information is stored, expressions can complete complicated information processing.

1. Basic JavaScript Data Types

In JavaScript, there are four basic data types: Numeric integers and real numbers), string-type characters or values enclosed by "" or ""), Boolean to True or False) and null.

2. Constants

◆ Integer constants

A JavaScript constant is also called a literal constant, which cannot be changed. Its Integer constants can be expressed in hexadecimal, octal, or decimal notation.

◆ Real constants

A real constant is represented by an integer plus a decimal part, for example, 12.32 or 193.98. It can be represented in scientific or standard methods: 5E7, 4e5, etc.

◆ Boolean Value

A boolean constant has only two States: True or False. It is mainly used to describe or represent a state or sign to describe the operation process.

◆ Constant type

One or several characters enclosed by single quotation marks (') or double quotation marks. For example, "this?kofjavascript", "3245", and "ewrt234234.

◆ Null Value

JavaScript has a null value, indicating nothing. If you try to reference a variable without definition, a Null value is returned. After completing the constants in the JavaScript data type, let's take a look at the concept of variables.

3. Variables

Variables are mainly used to access data and provide containers for storing information. For a variable, you must specify the name, type, declaration, and scope of the variable.

◆ Variable name

The naming of variables in JavaScript is very similar to that in computer languages. Note the following:

A. It must be A valid variable, that is, the variable must start with A letter, and numbers such as test1,

Text2. Except for the underscore (-), the variable name cannot contain spaces, (+ ),

(-), (,), Or other symbols.

B. JavaScript keywords cannot be used as variables. More than 40 defined in JavaScript

Keywords, which are used internally and cannot be used as the variable name. Such as Var,

Int, double, and true cannot be the names of variables. When naming a variable, it is best

Meaning corresponds to the meaning to avoid errors.

◆ Variable type

In JavaScript, variables can be declared using the command Var:

Varmytest;

This example defines a mytest variable. But it is not assigned a value.

Varmytest = "Thisisabook"

This example defines a mytest variable and assigns it a value.

In JavaScript, variables can be declared without being declared, and the type of variables is determined based on the data type during use. For example:

X = 100, y = "125", xy = True, cost = 19.5, etc.

X integer, y is the string, xy is the boolean type, and cost is the real type.

◆ Variable declaration and scope

JavaScript data variables can be declared and assigned values before use. Declare variables by using the var keyword. The biggest benefit of declaring variables is the ability to detect errors in the code in a timely manner. Because JavaScript uses dynamic compilation, it is not easy to find errors in the Code, especially the variable naming. There is also an importance for variables-that is, the scope of the variables. Global variables and local variables are also available in JavaScript. Global variables are defined outside all function bodies, and their scope is the whole function. Local variables are defined within the function body and only visible to this function, other functions are invisible.
 

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.