typeof total six kinds of data formats return

a total of six kinds typeof return data formats:

1、object 

2、undefined

3、string

4、number

5、boolean

6、function

Special attention typeof [] and Object typeof null is returned, typeof to the original type, in addition  null can display the correct type

The results typeof (Object) and typeof (Array) is a function, because Object and Array itself is built-in functions.

 

javascript type of data:

In ECMAScript contains two values of different data types: 基本类型值 and  引用类型值. 基本类型值It is a simple  data segments , and  引用类型值 those values may be composed of a plurality of  objects .

Basic data types : Undefined, Null, Boolean, Number, and  String、symbol(symbol ES6 are the new data type)

  Accessed by value, because you can operate the actual value stored in the variable.

  First of all primitive types are stored value, there is no function can be called, for example, undefined.toString(),但 '1'.toString() 是可以使用的。其实在这种情况下,'1' 已经不是原始类型了,而是被强制转换成了 String 类型也就是对象类型,所以可以调用 toString 函数。

Reference data (object) type :Object,array,function ( 基本上所有的对象最终都是继承于Object(null和undefined没有原型对象),)

  Different object types are primitive types and primitive types are stored value, the stored object type is an address (pointer). When you create an object type, the computer will help in memory, we open up a space to store value, but we need to find the space, which will have an address (pointer).

  Let's look at an example:

function test(person) {
person.age = 26
person = {
name: 'yyy',
age: 30
}

return person
}
const p1 = {
name: 'yck',
age: 25
}
const p2 = test(p1)
console.log(p1) // {name:'yck',age:26}
console.log(p2) //  {name:'yyy',age:30}

  • First, the function is passed a copy of the parameter passing pointers to objects
  • Internal function to modify the properties of the parameters of this step, I believe we all know, the current  p1 value is also modified
  • But when we re to  person the allocation of a target there have been differences

 So we finally  person have a new address (pointer), and there is  p1 no relationship, resulting in the value of the final two variables are not the same.

javascript data types in some small knowledge:

1.0.1 + 0.2 = 0.3?

In JS, 0.1 + 0.2 is not equal to 0.3, 0.1 in by the computer as a binary representation, then, will produce an infinite loop bits. Similar to decimal, one third is infinite decimal.

Therefore, when the mathematical operation of these recurring decimal, when converted to decimal and binary data, but also wireless or decimals, the end of the interception, that is, a value obtained .30000000000000004

Correct comparison method is to use the minimum precision values ​​provided JS, left and right sides of the equation to check whether the absolute value of the difference is less than the minimum precision:

Math.abs(0.1 + 0.2 - 0.3) <= Number.EPSILON   (true)

The difference between 2.666 and the new Number (666) of

123 is a number of digital type, and Number The (123) is a data object type.

‘HELLO'.charAt(1) ==》 'E'

Dot (.) Operator provides a packing operation, a temporary object will be constructed according to a basic type, it is possible to call the corresponding object on the basis of the type of method

3. parseInt 和 parseFloat

parseInt (string, radix) ------- convert a string to an integer number type

parseInt ignores spaces in front of the string until 2,904,628,156 to find the first non-space character, if the first character is a numeric character will continue to resolve the second character, until it encounters a non-numeric characters stop, if the first is not a number character, the method returns NaN, no longer continue to perform other operations.

 parseInt detect all integer format, such as: octal, decimal, hexadecimal, it may receive a second parameter to be converted to decimal number

parseFloat ------- converts the digital string into float type

  () Is similar to the processing of the method and the parseInt, view each character starts from the position 0, until you find the first non-active character, and the character string before conversion to digital.
However, for this method, the first occurrence of a decimal point is a valid character. If there are two decimal points, a second decimal point will be considered invalid, parseFloat
() method of the string before the decimal point will convert to digital. This means that the string "22.34.5" will be resolved to 22.34.
Use parseFloat () method is another difference is that the string must be expressed in decimal floating-point form, rather than using octal or hexadecimal.

Guess you like

Origin www.cnblogs.com/ffdh6868/p/11688835.html