no nonsense, straight to the question.I. Variable type and calculation
What types of typeof can be used in 1.1 JS?
Answer: 1. Value type VS reference type
typeof undefined //undefinedtypeof ' abc ' //stringtypeof 123 //numbertypeof true //booleantypeof {} //objecttypeof [] //objecttypeof null //objecttypeof console.log//function
1.2 when to use = = = When to use = =?
A: Coercion type conversion: string concatenation, = = operator, if statement, logical operation, the rest of the whole use of the three equals sign
1 = = ' //true 2 0== ' //true 3 null = undefined //true 4 if (obj.a = = null) {5 //here equals OBJ.A = = = NULL | | OBJ.A = = = Abbreviated form of undefined 6 //This is the recommended notation in the jquery source code 7} 8 Console.log (&& 0) //0 9 console.log ("| | ' abc ') //' abc ' Console.log (!WINDOW.ABC) //TRUE11 12//Determine if a variable will be treated as true or false13 var a = 10014 Console.log (!!) A
What are the built-in functions of 1.3 js?
Answer: Data Encapsulation Class object
Object, Array, Boolean, number, String, Function, Date, RegExp, Error.
1.4 JS Variable According to the storage mode of what type, and describe its characteristics
1 //value type2 varA = 103 varb =a4A = 115Console.log (b)//Ten6 7 //Reference type8 varObj1 = {x:100}9 varObj2 =obj1Tenobj1.x = 200 OneConsole.log (obj2.x)// $
1.5 How do I understand json?
Answer: JSON is just a JS object.
Json.stringify ({a:10,b:20})
Json.parse (' {"A": Ten, "B": 20} ')
Ii. Prototype and prototype chainKnowledge Points:
1. Constructors
2. Prototype five major rules
All reference types (arrays, objects, functions), all with object attributes, are free to extend properties (except for "null");
All reference types (arrays, objects, functions) have a _proto_ property (an implicit attribute), and the property value is an ordinary object;
All functions have a prototype attribute (explicit attribute), and the property value is also a normal object;
All reference types (arrays, objects, functions), _proto_ attribute values to the "prototype" property values of its constructors;
When trying to get a property of an object, if the object itself does not have this property, it will look for its _proto_ (that is, its constructor's prototype).
3. Prototype chain
4.instanceof: Method used to determine which constructor the reference type belongs to
F _proto_ one layer to the top, can correspond to Foo.prototype, and then try to Judge F.instanceof Object.
2.1 How to determine exactly if a variable is an array type?
var arr =instanceof Array //truetypeof arr // Object //typeof is unable to determine whether the array is = = = ' [object array] ';
2.2 Write an example of a prototype chain inheritance.
For:
varParent =function(name) { This. Name = Name | | ' Parent ' ;} ; Parent.prototype.getName=function(){ return This. Name; ; Parent.prototype.obj= {A:1} ;varChild =function(name) {parent.apply ( This, arguments);} ; Child.prototype=Parent.prototype;varParent =NewParent (' Myparent ') ;varChild =NewChild (' MyChild '); Console.log (Parent.getname ()); //myparentConsole.log (Child.getname ());//MyChild
2.3 Describes the process of a new object.
iii. scope and closures
3.1 Talk about the understanding of variable promotion
Function declarations are promoted, general variables and variable expressions are not promoted
3.2 Description of this several different usage scenarios
A: 1. Perform as a constructor function
2. Performing As Object properties
3. Perform as a normal function
4.call,apply,bind
//Call , apply, bindfunctionfn1 (name,age) {alert (name) Console.log ( This)}fn1.call ({x:' Lily ', 20)//eject Lily,this ={x:100}functionfn2 (name,age) {alert (name) Console.log ( This)}fn2.apply ({y:200},[' Lily ', 20]))//eject Lily,this ={y:200}varFn3 =function(name,age) {alert (name) Console.log ( This)}.bind ({z:300}) Fn3 (' Lily ', 20)//eject Lily,this ={z:300}
3.3 Create 10 <a> tags, click on the time to bounce out the corresponding serial number
var I for (var i = 0; i < i++) { (function(i) { var a = Document.createe Lement (' a ') = i + ' <br> ' a.addeventlistener (' click ',function (e) { e.preventdefault () alert (i)} ) Document.body.appendChild (a) }) (i)}
3.4 How to understand scopes
1. Free variables
var a =function F1 () { var b = F2 () { var c=300 // Current scope has no defined variable, i.e. "free variable" // free variable Console.log (b) // Free Variables Console.log (c) }}
2. Closures
function F1 () { var a = + // returns a function (function as return value) return functions () { console.log (a) }}//F1 get a function var f1 = F1 () var a =F1 () //a=100
3.5 Application of closures in practical development
JS FAQ Summary One