Js browser parses the data type and type judgment

### browser parses:
- 1. When the browser (core engine) when parsing and rendering js, js will provide a running environment, this environment is called "global scope (back-end global / customer service side window scope)"
- 2. The code is executed from top to bottom (there is a variable-up phase before)
=> Basic data type value, stored in the current scope
```
There are a = 12;
var b = a; js code itself is the stack memory operating environment, the basic types are stored in the stack memory for storing a billing location.
b = 13;
console.log(a);

There obj1 = {n: 100};
var obj2 = obj1; heap memory subject to the type of information values ​​stored in the reference object storage is the key-value pairs, the code string stored function matter
obj2['n'] = 200;
console.log(obj1.n); //=>200
```
There are a = 12;
var b = 13; a and b does not have any relationship, according to the value of the operation
1) First, open up a space to store 12
2) a statement of the current variable scope a (var a)
3) make that statement variables and storage of associates 12 (12 assigned to storage to a => assignment called definitions)
=> The basic types are re-assignment, basic data types, also known as a value type, in accordance with the values ​​of actions: a copy of the original value, into a new location on the space and nothing to do with the original value

=> Values ​​of reference types can not be stored directly to the current scope, (because the content may be stored too complicated) We need to open up a box of new space (ie warehouse), the contents stored in this space
 
There obj1 = {n: 100};
1) First, open up a new memory space, the key object of this stored (in order to ensure that the back can be found in this space, this space hex)
2) declare a variable, so variable and associated with an address space (the space assigned to the variable)

Reference type is not a value to follow, what space it operates references address: the address of the original space assignment to a new variable, but the original space there is no other clone, or a space, so there are a number of variables associated with the same Space,
Value type not let two variables associate, associate reference types will.
* Scope of memory called stack memory inside

###
- 1. The global scope formed
- 2. The code is executed from top to bottom
Open up a new memory heap, the heap memory key-value pair storage
n:10,
m: obj.n * 10 => obj.n case heap memory storage information is not completed yet, no address space in this case is given obj obj underfined, obj.n is underfined.n
```
var obj = {
n:10,
m: obj.n*10
};
console.log(obj.m);
VM165:3 Uncaught TypeError: Cannot read property 'n' of undefined
at <anonymous>:3:11
```
Get out is correct:
```
var obj = {
n:10,
};
obj.m =obj.n*10;
console.log(obj.m);
=> VM207:6 100
```
The judge sentences ### js
- 1.if / else / else if
```
var num = 12;
if (num>10){
a ++;
} else if(num>=0 && num <=10){
on one--;
} else {
a + = 2;
}
console.log(num); =>13
```
* There is a `conditions are met, regardless of whether there are behind the establishment of the conditions, not in judgment executed`
How to write about the conditions?
//> = / <= / == (like conventional comparative) 4% 2% Remainder => 0
```
if(0){
// => No matter what is written in the conditional, the final total should calculate its true / false judgment condition is established (the other value into a Boolean type, only 0, NaN, '', null, underfined is false, the rest is true)
}

if('3px'+3){
// => in the js + - * /% of all mathematical operations other than +. Remaining time operator, if they are non-numeric type value, is first converted to a digital type (Number), and then performing the operation
'3px'+3 => '3px3'
}
if ('3px'-3){
'3px'-3 => NaN
}
if(NaN>3) =>FASLE
 
grammar:
if(({})>5)
Syntax directly test console ({})> 5 'str'> 5
```
BAT face questions:
```
var num = parseInt('width: 35.5px');
if (num==35.5){
alert(0);
}else if (num==35){
alert(1);
} Else if (num == NaN) {// => NaN, and any number not equal
alert(2);
}else if (typeof num=='number'){
Are // => alert output string format '3'; alert (3)
// => the first operator typeof num
// => do compare
}else {
alert(4);
}

```

### typeof
> One of several ways js detection type, the other
> instanceof
> constructor
> Object.prototype.toString.call()

```
Syntax: typeof [value] => detection value data type
Return Value: detected result is a string of data contains the type Yes. For example: "number" / "string" / "boolean /" underfined "/" object "/" function "
typeof 12 =>"number"
typeof null => "object" as the representative null null object pointers (no memory space)
typeof function(){} =>"function"
typeof /^/ =>"object"
typeof true =>"boolean"
```
`* Typeof array detection / regular / object, and returns are" object, the drawbacks is that the object can not be broken. "`

Interview questions:
```
console.log(typeof []) =>"object"
console.log(typeof typeof []) =>type "object" => "string"
```



Guess you like

Origin www.cnblogs.com/fron-tend/p/11968198.html