Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created January 30, 2015 01:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idmontie/fa79747f72f0a1c0f362 to your computer and use it in GitHub Desktop.
Save idmontie/fa79747f72f0a1c0f362 to your computer and use it in GitHub Desktop.
JavaScript Interview Questions

How can you declare a class in JavaScript?

There are two main ways:

Option 1

function MyObject() {
}

var object = new Object();

Option 2

var object = {
};

How would you organize your JavaScript code?

In general, you can use modules:

var app = app || {};
app.module = ( function () {
  return {}
} )();

If you are creating jQuery plugins though, I would follow the jQuery plugin format:

+function () {
  var module = function () {};
  
  function Plugin( selector, callback, option ) {
    // ...
  }

  var old = $.fn.module

  $.fn.module             = Plugin
  $.fn.module.Constructor = module

  // WAITFOR NO CONFLICT
  // ===================

  $.fn.waitFor.noConflict = function () {
    $.fn.module = old
    return this
  }
}();

What are the differences between == and ===?

== compares with casting, === compares values and types.

What are the differences between null and undefined?

null is an object with no value.

undefined is a type.

How does MVC work with JavaScript?

Powerful MVC frameworks for JavaScript exist, namely backbone.js and angular.js.

They help:

  • organize
  • maintain
  • create single-page apps
  • create reusable components

How do prototypes work? Or, how can you add a method to a class already defined?

AlreadyDefinedClass.prototype.newFunction = function () {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment