您的位置:首页 > 职场人生

前端面试问题集

2015-10-25 21:06 501 查看
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”);

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

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

What do you think of AMD vs CommonJS?

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.

What’s the difference between a variable that is: null, undefined 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?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: