In this article mainly describes data types, variables and so on.
First, comments
The purpose of annotations is to improve the readability of the code, and the content of the comment is not displayed in the page. Can be divided into single-line comments and multiple lines of comments two.
Single-line Comment: Add "//" before the content of the comment
Multiline comment: Start with "/*" andend with"*/"
Second, the variable
From a programming standpoint, a variable is a memory used to store a certain number of values.
(1) define the variable with the keyword VAR, the syntax is as follows:
var variable name ;
(2) naming rules:
I. variables must start with a letter, underscore, or dollar symbol
Ii. You can use any number of English letters, numbers, underscores, or dollar characters.
Iii. cannot be used JS keywords and JS reserved words.
Note: A variable must be declared before it is assigned a value.
Variables can be assigned repeatedly.
case-sensitive in JS.
Third, the data type
Six Types of data:
i.undefined Type: Declares a variable but is not initialized.
Var message;
Alert (message==undefined); True
Executing the typeof operator on a variable that is initialized returns the undefined value, and the typeof operator for the declared variable also returns the undefined value.
Ii. Null Type
The null type is the second data type with only one value, and this special value is null. from a logical point of view, NULL value represents an empty object pointer, which is exactly the same as using the typeof operator Detection NULL value will return " Object "the reason.
Var Car=null;
Alert (typeof car);//"Object"
In fact, theundefined value is derived from a null value.
Alert (null==undefined);//true
Iii. Boolean Type
It is important to note that the literal value ofBoolean literals is true and false is case-sensitive. That is,True and False ( as well as other mixed-case forms ) are not Boolean value, just an identifier.
To convert a value to its corresponding Boolean value, you can call the transform function boolean (),
Var message= "Hello World";
Var messageasboolean=boolean (message);
The following table shows the various data types and their corresponding conversion rules:
A value that converts the value of the data type to true to false
Boolean true False
String any non-empty string "" ( empty string )
Number any non-0 numeric value (including infinity) 0 and NaN
Object NULL for any objects
Undefined N/A ( not applicable ) Undefined
Iv.. Number type
(1) floating-point value, the so-called floating-point value, is that the number must contain a decimal point, and must have at least one digit after the decimal. Although there can be no integers before the decimal point, we do not recommend this notation.
(2) Range of values
Due to memory limitations,ECMAScript cannot save all the values in the world. It can represent the minimum value saved in number.min_value , in most browsers middle-aged, this value is 5e-324; The maximum value that can be represented is saved in the Number.MAX_VALUE In most browsers, this value is 1.7976931348623157e+308.
(3) NaN
In ECMAScript , any number divided by 0 returns NaN, so it does not affect the execution of other code.
It itself has two features:
Any operation that involves nan will return nan
NaN is not equal to any value including itself.
For these two features,ECMAScript defines the IsNaN () function.
Alert (IsNaN (NaN));//true
Alert (IsNaN);//false
Alert (IsNaN ("ten"));//false
Alert (IsNaN ("Blue"));//true
Alert (IsNaN (true));//false
(4) Numeric conversion
3 functions:number (),parseint (),parsefloat ().
v.string Type
The string type is used to represent a sequence of strings consisting of 0 or more of the four-bit Unicode characters. Can be represented by single or double quotation marks.
VI. Object Type
the object in ECMAScript is actually a set of data and functions. An object can be created by executing The new operator followed by the name of the object type to be created.
JS Basic Notes--basic article