Numeric Number: integer, decimal, hexadecimal numeric, numeric range, three specific numeric value

8. Data Type

8.1 Introduction to Data Types

  • Why do we need the data type

    In the computer, the required data occupy different storage spaces are different, in order to facilitate the required data into different memory size of the data, make full use of the storage space, thus defines the different data types.
    In simple terms, the data type is a class type of data. For example, the name "John Doe", age 18, these data types are not the same.

  • Variable data types

    Place where the variable is used to store values, they have names and data types. Data type of a variable determines how the bits are stored on behalf of these values to the computer's memory. JavaScript is a weakly typed or dynamic languages . This means that no type of variable declaration in advance, the program is running, the type will be determined automatically:

    var age = 10;        // 这是一个数字型
    var areYouOk = '是的';   // 这是一个字符串     

    Code runs, variable data type JS engine by the data type = variable value to determine the right , and after finished running, it is determined that the data type of the variable. JavaScript has dynamic typing, but also means that the same variables can be used as different types:

    var x = 6;           // x 为数字
    var x = "Bill";      // x 为字符串    
  • Data type classification

    JS data types fall into two categories:

    • Simple data types (Number, String, Boolean, Undefined, Null)

    • Complex data types (object)


8.2 simple data types

Simple data types (basic data types)

JavaScript in simple data types and their descriptions are as follows:


Numeric Number

JavaScript can both save integer numeric types, you can also save a decimal (floating point).

var age = 21;       // 整数
var Age = 21.3747;  // 小数     
  1. Numeric hexadecimal

    The most common band have binary, octal, decimal, hexadecimal.

      // 1.八进制数字序列范围:0~7
     var num1 = 07;   // 对应十进制的7
     var num2 = 019;  // 对应十进制的19
     var num3 = 08;   // 对应十进制的8
      // 2.十六进制数字序列范围:0~9以及A~F
     var num = 0xA;   

    At present, we only need to remember that in JS octal preceded by 0, hexadecimal preceded by 0x

  2. Numeric range

    The maximum and minimum values ​​in JavaScript

    • Maximum: Number.MAX_VALUE, this value: 1.7976931348623157e + 308

    • Minimum: Number.MIN_VALUE, this value: 5e-32

  3. Three special numeric value

    • Infinity, represents the infinite, greater than any value

    • -Infinity, on behalf of the infinitesimal, less than any value

    • NaN, Not a number, representing a non-numeric

  4. isNaN

    It used to determine whether a variable is non-numeric type, returns true or false

var usrAge = 21;
var isOk = isNaN(userAge);
console.log(isNum);          // false ,21 不是一个非数字
var usrName = "andy";
console.log(isNaN(userName));// true ,"andy"是一个非数字

Guess you like

Origin www.cnblogs.com/jianjie/p/12124356.html
Recommended