Chaining allows us to run multiple jQuery methods (on the same element) within a single statement.like this:
$(selector).doA().doB().doC()
Explain "deferreds".
The Deferred object, introduced in jQuery 1.5, is a chainable utility object created by calling the jQuery.Deferred() method. It can register multiple callbacks into callback queues, invoke callback queues, and relay the success or failure state of any synchronous or asynchronous function.
The Deferred object is chainable, similar to the way a jQuery object is chainable, but it has its own methods. After creating a Deferred object, you can use any of the methods below by either chaining directly from the object creation or saving the object in a variable and invoking one or more methods on that variable.
Simplely,the deferred object is the salution of callback function and aslo a asynchronous task runner.
What are some jQuery specific optimizations you can implement?
selector optimization
event delegation
Cache jQuery selector results
Minimize DOM operations
Avoid repeated object creation
Stop using jQuery when you only need selectors(you can import selector only)
What does .end() do?
End the most recent filtering operation in the current chain and return the set of matched elements to its previous state.
How, and why, would you namespace a bound event handler?
Event namespacing provides a way to manage specific event handlers. For example, a plugin could namespace its event handlers to make them easier to unbind while still using anonymous functions. To namespace an event, just suffix the event type with a period and a name
Name 4 different values you can pass to the jQuery method.
Selector (string)
HTML (string)
Callback (function)
HTMLElement
object
array
element array
jQuery Object etc.
What is the effects (or fx) queue?
Show or manipulate the queue of functions to be executed on the matched elements.
What is the difference between .get(), [], and .eq()?
.get() return a raw DOM element
[] equal .get()
.get(index):index could be a negative number
[index]:index >=0
.eq() return a jquery element
What is the difference between .bind(), .live(), and .delegate()?
Using the .bind() method is very costly as it attaches the same event handler to every item matched in your selector.
You should stop using the .live() method as it is deprecated and has a lot of problems with it.
The .delegate() method gives a lot of "bang for your buck" when dealing with performance and reacting to dynamically added elements.
That the new .on() method is mostly syntax sugar that can mimic .bind(), .live(), or .delegate() depending on how you call it.
The new direction is to use the new .on method. Get familiar with the syntax and start using it on all your jQuery 1.7+ projects.
What is the difference between $ and $.fn? Or just what is $.fn.
$ = function(){}
$.fn = $.prototype = {};
Optimize this selector: javascript $(".foo div#bar:eq(0)")
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all children matching a selector, whether those children exist now or are added in the future.the underlying cause is browser's event bubbling ;
Explain how this works in JavaScript
The this object is bound at runtime based on the context in which a function is executed:
when used inside global functions,this is equal to window in nostrict mode and undefined in strict mode.
whereas this is equal to the object when called as an object method.
as a constructor
call and apply
bound functions
as dom event handler
Explain how prototypal inheritance works
Whenever a function is created, its prototype property is also created according to a specific set of rules.
When it comes to inheritance, JavaScript only has one construct: objects. Each object has an internal link to another object called its prototype. That prototype object has a prototype of its own, and so on until an object is reached with null as its prototype. null, by definition, has no prototype, and acts as the final link in this prototype chain.
How do you go about testing your JavaScript?
Grunt/Karma + Jasmine/QUnit
AMD vs. CommonJS?
What's a hashtable?
Hashtable is a data structure that associates keys with values;
Explain why the following doesn't work as an IIFE: function foo(){ }();.
What needs to be changed to properly make it an IIFE?
The most widely accepted way to tell the parser to expect a function expression is just to wrap in in parens, because in JavaScript, parens can’t contain statements. At this point, when the parser encounters the function keyword, it knows to parse it as a function expression and not a function declaration.
What's the difference between a variable that is: null, undefined or undeclared?
How would you go about checking for any of these states?
the undefined variable is a declared but has a value of undefined. To use a undeclared variable will cause an error.
What is a closure, and how/why would you use one?
Closures are functions that have access to variables from anthor function's scope.
This is often accomplished by creating a function inside a function.
What's a typical use case for anonymous functions?
Explain the "JavaScript module pattern" and when you'd use it.
Bonus points for mentioning clean namespacing.
What if your modules are namespace-less?
The module pattern use a anonymous function that returns a object.
Inside of the anonymous function, the private variables and functions are defined first.
After that, an object literal is returned as the function value. That object literal contains only properties and methods that should be public.
Since the object is defined inside the anonymous function, all of the public methods have access to the private variables and functions.
How do you organize your code? (module pattern, classical inheritance?)
I developing SPA with requirejs and MVC Framework recently. So I organize my code with AMD.
What's the difference between host objects and native objects?
Native objects are those objects supplied by JavaScript. Examples of these are String, Number, Array, Image, Date, Math, etc.
Host objects are objects that are supplied to JavaScript by the browser environment. Examples of these are window, document, forms, etc.
Difference between:
function Person(){}
var person = Person()
var person = new Person()
These methods both call the function with a specific this value.
* the apply() method accepts two arguments: the value of this and an array of arguments.
* the call() method exhibits the same behavior as apply(),but arguments are passed to it differently.Using call() arguments must be enumerated specifically.
explain Function.prototype.bind?
ECMAScript 5 defines an addition method called 'bind()'.the 'bind()' method create a new function instance whose this value is bound to the value to that was passed into 'bind()'.
When do you optimize your code?
For release, we will compress and combine code.
Whenever I have a time I will review my code and refactor it.
Can you explain how inheritance works in JavaScript?
When would you use document.write()?
Most generated ads still utilize document.write() although its use is frowned upon
Use less as far as possible
What's the difference between feature detection, feature inference, and using the UA string
Feature Detection is to identify the browser's capabilities.
Feature Inference is guess whether browser has certain feature through others feature or UA string.
One inappropriate use of feature detection is called feature inference. Feature inference attempts to use multiple features after validating the presence of only one. The presence of one feature is inferred by the presence of another. The problem is, of course, that inference is an assumption rather than a fact, and that can lead to maintenance issues.
UA String is User-Agent Detection.
Explain AJAX in as much detail as possible
AJAX is short for Asynchronous Javascript + XML. The technique consisted of making server requests for additional data without unloading the page,resulting in a better user experience.
Explain how JSONP works (and how it's not really AJAX)
Have you ever used JavaScript templating?
If so, what libraries have you used? (Mustache.js, Handlebars etc.)
Handlebars
_.tmpl
$.tmpl
Explain "hoisting".
There is a preproccess or precompile in javascript runtime. and 'Hoisting' occur in the preproccess.
Function declarations and variable declarations are always moved (“hoisted”) invisibly to the top of their containing scope by the JavaScript interpreter. This means that code like this:
Event Flow describles the order in which events are received on the page.An event has three phases to its life cycle: capture, target, and bubbling. Event Bubbling mean that an event start at the most specific element(the deepest possible point to the document tree) and then flow upward toward the least specific node(the document);
What's the difference between an "attribute" and a "property"?
Often an attribute is used to describe the mechanism or real-world thing.
A property is used to describe the model.
In HTML / Javascript the terms get confused because DOM Elements have attributes (per the HTML source) which are backed by properties when those elements are represented as Javascript objects.
To further confuse things, changes to the properties can sometimes update the attributes.
For example, changing the element.href property will update the href attribute on the element, and that'll be reflected in a call to element.getAttribute('href').
However if you subsequently read that property, it will have been normalised to an absolute URL, even though the attribute might be a relative URL!
Why is extending built in JavaScript objects not a good idea?
Depend on the way of extending.
Why is extending built ins a good idea?
Depend on the way of extending.
Difference between document load event and document ready event?
ready means DOM is ready.
load means the page fully loaded. Includes inner frames, images etc.
What is the difference between == and ===?
The == operator will compare for equality after doing any necessary type conversions. The === operator will not do the conversion, so if two values are not the same type === will simply return false. It's this case where === will be faster, and may return a different result than ==. In all other cases performance will be the same.
Explain how you would get a query string parameter from the browser window's URL.
What's the difference between standards mode and quirks mode?
Obviously,the css box model.
What are the limitations when serving XHTML pages?
Are there any problems with serving pages as application/xhtml+xml?
The XHTML page must be well formed.If you forgot to closed a element and the browser will not to closed it and cause error.
For "application/xhtml+xml", some old browsers no supports.
How do you serve a page with content in multiple languages?
What kind of things must you be wary of when design or developing for multilingual sites?
Use i18n framework.
What are data- attributes good for?
The W3C specification for data-attributes states that:
Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.
Custom data- attributes are a great way to simplify the storage of application data in your web pages.
Consider HTML5 as an open web platform. What are the building blocks of HTML5?
more semantic text markup
new form elements
vedio and audio
new javascript API
canvas and SVG
new communication API
geolocation API
web worker API
new data storage
Describe the difference between cookies, sessionStorage and localStorage.
Now there are such way to keep data on front-end side.
HTML5 web storage
HTML5 local Storage
HTML5 session storage
HTML5 web database
Cookies
localStorage - stores data with no expiration date
sessionStorage - stores data for one session
HTML5 web storage = generic umbrella term for the new client-side data storage options:
Web Storage is more secure and faster. The data is not included with every server request, but used ONLY when asked for. It is also possible to store large amounts of data, without affecting the website's performance.
Local Storage = persistant and scoped to the domain(store data with no expiration date). At the moment two flavors are usually mentioned:
'default' = stores things in name/value pairs
Web SQL (aka Web Database) = uses a SQL database
Session Storage = non persistent and scoped only to the current window(stores data for one session)
Cookies = the old school way of doing all of the above. Stores name/value pairs per domain.
What UI, Security, Performance, SEO, Maintainability or Technology considerations do you make while building a web application or site?
So big question...
Talk about your preferred development environment. (OS, Editor, Browsers, Tools etc.)
win/Unix(Mac OS)
sublime text 2/3, visual studio,vi
chrome/firefox/ie9
browsers devTools,git,node
Can you describe your workflow when you create a web page?
study prototype
set structures(html tag)
render with style
add interactive by scripts
Can you describe the difference between progressive enhancement and graceful degradation?
Bonus points for describing feature detection
Graceful degradation
Providing an alternative version of your functionality or making the user aware of shortcomings of a product as a safety measure to ensure that the product is usable.
Progressive enhancement
Starting with a baseline of usable functionality, then increasing the richness of the user experience step by step by testing for support for enhancements before applying them.
I agree with progressive enhancement, and increaseing user experience with feature detection.For example,once i detectived that the browser support round-corner or shadow text,i will apply the futures to pages.
Explain what "Semantic HTML" means.
Semantic HTML is the use of HTML markup to reinforce the semantics, or meaning, of the information in webpages rather than merely to define its presentation or look. Semantic HTML is processed by regular web browsers as well as by many other user agents. CSS is used to suggest its presentation to human users.
As an example, recent HTML standards discourage use of the tag <i> (italic, a typeface)[1] in preference of more accurate tags such as <em> (emphasis); the CSS stylesheet should then specify whether emphasis is denoted by an italic font, a bold font, underlining, slower or louder audible speech etc. This is because italics are used for purposes other than emphasis, such as citing a source; for this, HTML 4 provides the tag <cite>.[2] Another use for italics is foreign phrases or loanwords; web designers may use built-in XHTML language attributes[3] or specify their own semantic markup by choosing appropriate names for the class attribute values of HTML elements (e.g. class="loanword"). Marking emphasis, citations and loanwords in different ways makes it easier for web agents such as search engines and other software to ascertain the significance of the text.
Semantic = Meaning.
Semantic elements = Elements with meaning.
How to write 'Semantic HTML'?
write correct tags
Semantics applies to IDs and Classnames as well as tags
html first, then css
always separate style from content
How would you optimize a websites assets/resources?
Looking for a number of solutions which can include:
File concatenation
File minification
CDN Hosted
Caching
...
Why is it better to serve site assets from multiple domains?
How many resources will a browser download from a given domain at a time?
Multiple domains could increase the number of parallel downloads that the browser can perform.
about 4 to 6 connections per domain
Not all browsers are restricted to just two parallel downloads per hostname. Opera 9+ and Safari 3+ do four downloads per hostname. Internet Explorer 8, Firefox 3, and Chrome 1+ do six downloads per hostname. Sharding across two domains is a good compromise that improves performance in all browsers.