关于前端:前端基础面试题HtmlcssJavascript2

闭包集体了解:

对于一些重要的变量,心愿可能封装到某一外部作用域,防止其全局净化 (任意更改)。通过返回一个函数,该函数可能操纵外部变量,暴露出拜访的办法。

 function fn1(){
       var n =0;
         return function add() {
                    n++;
                    console.log(n);
                      }
               }
               //实现了内部拜访外部变量。
  let f =fn1();
  f();//1
  f();//2
  f();//3

js根本数据类型和判断

六大数据类型:null,undefined,string,boolean,number,symbol

   1.typeof粗略判断:毛病:null,数组断定均视为对象
      let a =[1,2,3];  //object
      let b={name:"xmj"};//object
      let c=null; //object
      let d ='eeee';//string
   
   2.instanceof:原型链继承判断:原型链 null->object->([],function);
   从下到上查找最近的父原型。eg:let x =[], x instanceof Array ==true
   特点:能够辨别[]和{};[].__proto__ =Array.prototype;
   即数组的instanceof是Array,而对象的最近父原型是Object;
   
   3.constructor:相似instanceof
   4.Object.ptototype.toString:能够判断所有的像function,obj,和[]的区别。
   
   
   

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理