前端:预解释面试题

本人最近很无聊,好吧,技术渣一枚,因被预解释的题虐的体无完肤,本着预解释虐我千百遍我却待它如初恋的心态,多多多多的来练习,争取成为扫一眼就能得出答案的大牛,以下是找到的各种运算,比较,预解释,原型链的题。不懂的不要问我,因为我也不懂,(实在不会再来问我),如果你们也有,欢迎拿出来虐。不定期更新~
因为题很多,弄着弄着就乱了,不过大部分题型是一样,如果有重复就当是练习了。虽然现在es6比较流行,不会出现下面的问题,但预解释的快乐你想象不到,虐并快乐着
 1.
    console.log(1+2+'3')
    console.log('3'+2+1)
    console.log(3+4+'5'+5+1)
    console.log(+'3'+2+1)
    console.log(1+ +'3'+2+1)
    console.log(1+ +'2'+'3')
    console.log('A'-'B'+'C')
   console.log('C'+'A'-'B')
    console.log(0&&2||1)
    console.log(0||2&&1)
    console.log(0&&2&&3||1||4)
   console.log(0||2||3&&1)
   console.log(0||2||3&&1&&4)
   console.log(0||1||2)
    console.log(0||1||2||3)
    console.log(0&&2&&1)
    console.log(0&&2&&1&&3)

2.
	var a=0.1,b=a+++a,c=a--+b;
	   console.log(a,b,c)
3.
	(function(){
	      var a=b=9;
	  })();
	    console.log(a);
	    console.log(b);
4.
	function aa() {
	      var a=b=9;
	  }
	  console.log(a);
	  console.log(b);

5.
	function aa() {
	      var a=b=9;
	      console.log(a);
	      console.log(b)
	  }
	  aa()
  
  6.
	function aa() {
	      var a=b=c=9;
	      console.log(a);
	      console.log(b)
	      console.log(c)
	  }
	  aa();
	  console.log(a);
	  console.log(b);
	  console.log(c);
7.
(1)第一题:

f = function () { return true; };
g = function () { return false; };
(function () {
    if (g() && [] == ![]) {
        f = function f() { return false; };
        g = function() { return true; }
    }
})();
alert(f());

输出的结果是true ,函数的声明会被提前,但是函数表达式是不会被提前的,在if条件判断中的f和g均为函数表达式,所以均不会被提前,
使用全局的变量进行判断,,if中的结果如下:

1 var s1 = g();//false
2 var s2 = g() && []; //false
3 var s3 = ![]; //false
4 var s4 = g() && [] == ![]; //false(此处注意运算符的优先级条件运算符的优先级高于逻辑运算,所以先执行后面的,在执行前面的)
5 var s5 = (g() && []) == ![]; //true
6 //所以最后的结果为true。
(2)如果将上面的稍作改变结果会是怎样呢?


1 f = function () { return true; };
2 g = function () { return false; };
3 (function () {
4     if (g() && [] == ![]) {
5         f = function f() { return false; };
6       function g() { return true; }  //(1)
7     }
8 })();
9 alert(f());
此题中if中的g函数的声明会被提前,但是定义不会被提前,所以if中使用的将不会 是全
局的函数g,而是局部变量,但是虽然g进行了声明,但是没有定义故会报错g is not a function 。
如果将(1)式变为 var g = function(){};这样也会报同样的错误,但是后者相当于是函数表达式,
提升的是var定义的变量而不是函数的声明,这一点要注意区分的。
8.
	(function f(){
	    function f(){ return 1; }
	    alert (f());
	    function f(){ return 2; }
	})();
9.
	var a=12;
	function show(){
	    alert(a);
	    a=15;
	}
	show();
	alert(a);
10.
	var a=12;
	function show(){
	    alert(a);
	    var a=15;
	}
	show();
	alert(a);
11.
	var uname = 'jack'
	function change() {
	    alert(uname)
	    var uname = 'fofoxqi'
	    alert(uname)
	}
	change()
12.
	function change() {
	    alert(typeof fn)
	    function fn() {
	        alert('hello')
	    }
	    var fn
	}
	change();
13.
	function abc(){
	    a=12;
	    alert(a);
	}
	function b(){
	    alert(a)
	}
	abc();
	b();
14.
	fu
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值