The JavaScript scripting language, like other languages, has its own basic data types, expressions and arithmetic operators, and the basic frame structure of the program. JavaScript provides four basic data types for handling numbers and text, while variables provide the place where information is stored, and expressions can perform more complex processing.
1. Basic Data type
Four basic data types in javascript: numeric values (integers and real numbers), string literals (characters or values enclosed by "" or "), Boolean (make True or false), and null values.
2, constant
• Integral type Constants
JavaScript constants are often called literal constants, which are data that cannot be changed. Its integer constants can represent their values using 16, octal, and decimal.
• Real Constants
A real constant is represented by an integer part plus a decimal part, such as 12.32, 193.98. Can be expressed in scientific or standard way: 5E7, 4E5, etc.
• Boolean value
There are only two states of a Boolean constant: TRUE or false. It is mainly used to describe or represent a state or a flag to illustrate the operation process.
• Character-type constants
Use one or more characters enclosed in single quotes (') or double quotes ("). such as "This are book of JavaScript", "3245", "ewrt234234", and so on.
• Null value
There is a null value in JavaScript that means nothing. If you attempt to reference a variable that is not defined, a null value is returned.
3, variable
The main function of variables is to access data and provide containers for storing information. For a variable, you must specify the name of the variable, the type of the variable, the declaration of the variable, and the scope of the variable.
• Name of variable
The naming of variables in JavaScript is very similar to their computer language, and here are two points to note:
A, must be a valid variable, that is, the variable begins with a letter, the middle can appear numbers such as Test1,
Text2 and so on. With the exception of the underscore (-) as a hyphen, the variable name cannot have spaces, (+),
(-), (,), or other symbols.
b, you cannot use a keyword in javascript as a variable. More than 40 defined in JavaScript
Keyword, these keys are used internally and cannot be the name of a variable. such as Var,
int, double, true cannot be the name of a variable. When you name a variable, it's best to put the variable
Meaning corresponds to the meaning of its representative, lest there be any mistake.
• Type of variable
In JavaScript, a variable can be declared with the command var:
var mytest;
This example defines a mytest variable. But there is no value assigned to it.
Var mytest= "This is a book"
The example defines a mytest variable and assigns its value.
In JavaScript, a variable can be declared without a declaration, and the type of the variable is determined by the type of the data when it is used. For example:
x=100, y= "125", xy= True, cost=19.5, etc.
where x is an integer, Y is a string, XY is a Boolean, and the cost is solid.
• Declaration of variables and their scope
JavaScript variables can be declared before use and assignable. Declare a variable by using the var keyword. The greatest benefit of declaring a variable is the ability to detect errors in the code in a timely fashion, because JavaScript is dynamically compiled, and dynamic compilation is not easy to detect errors in code, especially in terms of variable naming. There is another importance to a variable-that is, the scope of the variable. There are also global variables and local variables in JavaScript. Global variables are defined outside the body of all functions and are scoped to the entire function, while local variables are defined within the function body and are visible only to the function, but not to other functions.