Why I'm Not A JavaScript Developer
Answering the Front-end developer JavaScript interview questions to the best of my ability.
Sometimes you need to delegate events to things.
this
works in JavaScriptThis references the object or "thing" defined elsewhere. It's like "hey, thing I defined elsewhere, I'm talkin' to you."
When you inherit a prototype coded by someone else and you don't know what the hell is going on with it.
Step 1: weep. Step 2: plunk around on StackOverflow for a couple hours. Step 3: copy and paste until it works. Step 4: merge feature branch and deploy to dev environment to queue for continuous integration. Just kidding, I have no idea what that means.
AMD, or the Association of Mannequin Deconstruction, is a unionized organization dedicated to deconstructing mannequins at stores that are going out of business. CommonJS is JavaScript written by commoners. Like me.
function foo(){ }();
Because those IIFEs are always messing shit up. Stupid IIFEs..
Put the official IIFE hat on it, and follow the official IIFE induction ceremony protocol.
null
, undefined
or undeclared
?Null variables are SOL. Undefined variables haven't been defined yet. Undeclared variables won't make it through customs at the airport.
Ask for ID.
Sometimes important events happen, often leaving lingering questions behind. Getting closure allows us to come to terms with these events and move on with our lives.
Sometimes you don't want people to see the functions you're writing, so you do all your debugging in a private tab in Chrome. Or you can use Tor.
I try to color-code things, so I spend a lot of time getting my syntax highlighting just right.
Host objects consist of unleavened bread and are distributed to some people on Sundays. Native objects are deployed to native environments (via PhoneGap)
function Person(){}
, var person = Person()
, and var person = new Person()
?The wonderful thing about people is that they come in all shapes and sizes. They have different personalities and aspirations.
.call
and .apply
?Calls are made on iPhones (or Androids). Applying is how you get a job.
Function.prototype.bind
.The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called. (I just copied and pasted this from MDN)
Normally I wait an hour after I eat to optimize my code, to be safe.
document.write()
?When I make banner ads.
Feature detection involves testing for the presence of a particular feature. Feature inference is making some assumptions about the presence of a feature. UA detection is the spawn of Satan.
Ajax is a brand of cleaning products, introduced by Colgate-Palmolive in 1947 for a powdered household and industrial cleaner. It was one of the company's first major brands.The ingredients of its scouring cleanser product include sodium dodecylbenzenesulfonate, sodium carbonate, and quartz. The Ajax name was successfully transferred to an entire line of household cleaning products and detergents; the line enjoyed its greatest success in the 1960s and early 70s. Ajax All-Purpose Cleaner with Ammonia, introduced in 1962, was the first major competitor to Mr. Clean, which Procter and Gamble debuted in 1958. Ajax' success as the so-called "White Tornado" forced Procter and Gamble to introduce its own ammoniated cleaner, Top Job, in 1963.
JSONP works like a charm, and it's different than AJAX in that it's not a household cleaning supply.
Used mustaches sound gross, but I suppose I have used Mustache.js before.
Sometimes you really gotta get in there, spit on your hands, and lift that sucker up over your head like you mean it.
Here's a link to the IMDB page for the Butterfly Effect, starring Ashton Kutcher. It would do a better job at explaining event bubbling.
Everyone's got attributes. Some good. Some bad. As sad as it is to say, not everyone owns property. Though a discussion about economic inequality might be out of scope for an interview like this.
I mean, the things are already built. Just leave 'em be, or you'll mess 'em up. Hands off, pal!
document load
event and document ready
event?Document load means the document has loaded. Document ready says "hey, I'm ready to go!"
==
and ===
?This one is almost too easy. One has an extra "=".
Same-origin policy makes sure a bunch of third-party bullshit doesn't make it onto the page.
duplicate([1,2,3,4,5]); // [1,2,3,4,5,1,2,3,4,5]
How about this? [1,2,3,4,5,1,2,3,4,5]
Ternary means it involves three things, and strings 'em all on one line so it's harder to read.
use strict : JavaScript :: Harlem Globetrotters : Basketball
That sounds hard, and for some strange reason I'm suddenly jonesing for a Dr. Pepper.
We've only got one globe, man. If we ruin it, we'll all die off unless we can figure out how to colonize Mars real quick like.