前端面试问题集

  1. Ways to define functions

    Function Declration: function functionName(param1) {}

    Anonymous Function: var functionName = function(param1) {};

    Function Constructor: var myFunction = new Function(“a”, “b”, “return a * b”);

  2. What is Javascript Event Delegate?

    To bind the event listener to the parent of an html element. The reason for doing this is to easier adding and removing event listeners. For example, li inside ul, to do event delegation. We bind the click listener to ul, and then useevent.target.nodeName to find if it’s the exact node we want to bind the event to.

    More examples see http://davidwalsh.name/event-delegate

  3. Explain how this works in JavaScript

    Function:

    this point to the function itself.

    Object:

    When a function is called as a method of an object, its this is set to the object the method is called on.

    Simply speaking, this is pointing to one upper level of the element in most case.

    Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this

  4. What do you think of AMD vs CommonJS?

  5. Explain why the following doesn’t work as an IIFE: function foo(){ }();.

    Need a () to wrap the function body and declarations.

    1
    (function foo() {})()

    IIFE: An immediately-invoked function expression (or IIFE, pronounced “iffy”) is a JavaScript design pattern which produces a lexical scope using JavaScript’s function scoping.

  6. What’s the difference between a variable that is: nullundefined or undeclared? How would you go about checking for any of these states?

    undeclared:

  • A variable is undeclared when it does not use the var keyword. It gets created on the global object (that is, the window), thus it operates in a different space as the declared variables.

    undefined:

  • Something is undefined when it hasn’t been defined yet. If you call a variable or function without having actually created it yet the parser will give you an not defined error.

    null:

  • null is a variable that is defined to have a null value.

  • undeclared variables don’t even exist

  • undefined variables exist, but don’t have anything assigned to them
  • null variables exist and have null assigned to them

    First, use typeof to check the type of variable

    Second, null == undefined is true, null === undefined is false

What's the difference between host objects and native objects?     

转载于:https://my.oschina.net/jerryWu/blog/521838

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值