Recently do some projects found that their JS foundation is still not solid enough to read the Rhino book, deepen their understanding and impression. So from the beginning of this article, the back is about the native JS some of the content.
In this article, we describe one of the data types of JS in detail.
- The data types of JavaScript (hereinafter referred to as JS) fall into two categories: primitive Type and object type . The original types of JS include numbers, strings, and Boolean values.
- JS has two special primitive values:null (empty) and undefined (undefined), which are not numbers, strings, and Booleans. They typically represent unique members of their own special type, respectively.
- In addition to numbers, strings, Booleans, nulls, and undefined, the object is a collection of attributes, each of which consists of a "name/value pair" (the value can be the original value, such as a number, a string, or an object).
- The normal JS object is an unordered collection of named values. JS also defines a special object, an array, that represents an ordered set of numbered values. JS specifically defines the syntax for an array, which we will explain in detail later. Make the array have some unique behavior characteristics that are different from ordinary objects.
- JS also defines a special object-function. The function has an object that has executable code associated with it, runs the executable code by calling the function, and returns the result of the run. As well as arrays, functions behave differently from other objects.
- If a function is used to initialize (using the new operator) a newly created object, which we call a constructor , each constructor defines a class object
- below I specifically for you to explain the first type of data types-- number
- According to the number format in JS, the integer range that can be represented is the bounding value from -9007199254740992~9007199254740992 (that is, -253~253).
- In JS, when a number directly appear in the JS program, we call Digital Direct, JS support a number of digital direct volume format.
- An integer direct quantity that represents a decimal integer in a sequence of numbers, such as: 0 3 133333
- Floating-point direct volume, floating-point direct volume can contain a decimal point, for example: 3.14.3333 2.02e23 (2.02x1023) e or E for how many times the power
- Arithmetic operations in JS (+ (plus),-(minus), X (Multiply),/(except),% (take away)) in addition to these basic operators, JS also supports more complex arithmetic operations, which are implemented by functions and constants defined as properties of the Math object:
Math.pow (2, -)//2 of 53 power is 8007199254740992Math.Round (.6)//1.0 RoundingMath.ceil (.6)//1.0 Rounding upMath.floor (.6)//0.0 rounding DownMath.Abs (-5)//5 seeking absolute valueMath.max (x,y.z)//returns the maximum valueMath.min (x,y.z)//returns the minimum valueMath.random ()//generates a pseudo-random number greater than or equal to 0 less than 1Math.PI//π-PiMath.e//e base of natural logarithmMATH.SQRT (3)//square root of 3Math.pow (3,1/3)//Cubic root of 3Math.sin (0)//Trigonometric functions: also cos () and atan, etc.
-
- JS uses the IEEE-754 floating-point notation, which is a binary notation that can accurately represent fractions, such as 1/2, 1/8, and 1/1024, but our usual scores are decimal fractions 1/10/1/100 and so on. Binary floating-point notation does not accurately represent a simple number like 0.1.
0.3-0. 2 is not equal to 0. 2-0. 1, in the real operating environment 0.3-0.2=0.09999999999999998 and 0.2-0.1=0.1
This is caused by rounding errors
The content of the number type is probably finished, and the next chapter I'll tell you about the second type of data--the string
Data type of JS