Here are some of the questions he asks to assess the depth of a Web developer’s knowledge of the platform:
Which of jQuery’s asynchronous features have you used?
- What Most People Say: “I’ve used $.ajax’s success callback to update the page after getting a response from the server. Occasionally, I end up with a bug in the code and I’m not sure why.”
- What You Should Say: “I’m familiar with several asynchronous features, and I use Promises to manage them. For instance, when I make an Ajax call, I use Promises to update the page after getting a response from the server. This allows me to separate my data retrieval from what I’m going to do with that data… which avoids strong coupling.”
Are there any parts of the jQuery library that you don’t use because they’re no longer best practices?
- What Most People Say: “Hmm, I haven’t given it much thought.”
- Why You Should Say It: Having an opinion points to greater experience with jQuery’s library. Considering system design and alternative approaches, and viewing Web development with an architect’s eye, is the sign of a highly competent developer. In addition, a good developer will dig into an API’s documentation and form an opinion about it. Understanding how an API works may reveal additional uses and benefits.
What is event delegation and why is it beneficial?
- What Most People Say: “Event delegation makes binding more efficient and events easier to manage.”
- What You Should Say: “Event delegation refers to the process of using event propagation (bubbling) to handle events at a higher level in the DOM. It creates efficiencies in several ways. First, I don’t have to rebind or unbind event handlers when I add more elements to the DOM, which makes binding faster and easier to reason about. Second, there are less overall handlers on the page, which saves on memory.”
- Why You Should Say It: A competent developer will demonstrate an understanding of the event bubbling system that operates underneath jQuery, as well as the inner workings of event delegation.
You have a Web page with an open dialogue box. You want to close the open dialogue when a user clicks outside the box and leave it open when a user clicks inside the box. How would you go about it?
- What Most People Say: “I would use a jQuery plugin that handles this behavior for me. If I don’t have one, I suppose I can add an event listener on the body of the page that closes the dialog on click if the target of the click isn’t the dialogue.”
- What You Should Say: “I would set up two event listeners, one on the body of the Web page, the other on the dialog itself. The one on the body closes any open dialogue box. The one of the dialog itself uses stopPropagation to cancel the propagation of any clicks, so that the event will never bubble to the body if the event happens inside the dialogue box, thus preventing it from closing.”
- Why You Should Say It: The second method is definitely the better way to go; it not only reduces bugs, but also demonstrates an in-depth understanding of how to manage event bubbling.