前端工程师面试题总结 - JavaScript(1)

1. Describe closure

Simply accessing variables outside of your immediate lexical scope creates a closure.

For example:

var test = function () {

    var count = 0;

    var addOne = function(){ count += 1;}

    return addOne;

}

var t = test();    // here t refers to the addOne function, and since addOne refers to the test object, the whole test object will be stored in the RAM

t();  // now the count equals to 1

2. What is event bubbling

Event bubbling and capturing are two ways of event propagation in HTML DOM.
In bubbling the event is first captured and handled by the inner most element and then propagated to outer elements.
In capturing the event is first captured by the outer most element and propagated to the inner most element.
Both are part of the W3C standard. As per the standard first the event will capture it till it reaches the target then it will bubble up to the outer most element.
We can use the addEventListener(type, listener, useCapture) to register event handlers for bubbling and capturing phases. To use the capturing phase event handling pass the third argument as true.
IE uses only event bubbling where as firefox supports both bubbling and capturing.
Only event bubbling model is supported by all the major browsers. So if you are going to use event capturing still you need to handle event bubbling for IE. So it will easier to use event bubbling instead of capturing.

P.S: other questions like have you used Angular.js, node.js, or any other similar libraries. Learn as much as you can.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值