Study JavaScript for Interviews

I have an upcoming job interview and have been doing my JavaScript research and review. Here is a great list of JavaScript resources that I’ve been using:

JavaScript Closure:
JavaScript Hoisting:

Mozilla Developer: Re-Intro to JS


CodeAcademy – Free

CodeSchool – Free / $25-month:
Some courses are free, the rest require membership $25 / month, but if you’re job hunting get it for a month!)
jQuery, JS, & CSS and HTML:

W3 Schools JS:

 Quick Notes

-Everything is an object
-JavaScript does not have Classes, but it does have prototypes


Object literal

var person={name:"David",age:24};

Direct Instance (pretty much same as object literal)

var person = new Object(); // {}; is the preferred syntax."david";
person.getName = function () {

Constructor with private, privileged and public methods

function Person(fName, lName, age){
  // Public properties
  this.firstname = fName;
  this.lastname = lName;

  // Private properties: use var for private.
  // accessible to local private methods and to privileged functions
  var privateName = fName+"secrets";

  // Private method
  function privateFunc(){
    // This function can access private vars and methods.
    // Can only be called from within Person.

  //Privileged method
  this.privilegedFunc = function(){
    // This function can access private vars and methods.
    // Can be called from outside or inside Person

Person.prototype.publicFunc = function(){
  //this public function can only access public properties of Person
  return this.age;

Scoping: private, public, priviliged

Private and privileged members can only be made when an object is constructed.

Private: must be inside the constructor. Use var for private properties, and for private methods use: function funcName(){…};

Privileged: method is able to access the private variables and methods, and is itself accessible to the public methods and the outside. It is possible to delete or replace a privileged method, but it is not possible to alter it, or to force it to give up its secrets.

Public: For best memory usage add public functions to the object’s prototype



Three ways to call Methods


//V2: call first param is the context, can be null, then pass the method's params,"Burp");

//V2.5: apply same as call, but method's params are passed as an array


-point child to parent prototype

// define the Student class
function Student() {
  // Call the parent constructor;
// inherit Person
Student.prototype = new Person();

// correct the constructor pointer because it points to Person
Student.prototype.constructor = Student;

Interfaces (don’t exist)
There’s no notion of “this class must have these functions” (that is, no interfaces per se), because:
1. JavaScript inheritance is based on objects, not classes. That’s not a big deal until you realize:
2. JavaScript is an extremely dynamically typed language — you can create an object with the proper methods, which would make it conform to the interface, and then undefine all the stuff that made it conform. It’d be so easy to subvert the type system — even accidentally! — that it wouldn’t be worth it to try and make a type system in the first place.

-if you need to make sure an object has a certain function, do it like this:

if (typeof(someObject.quack) == "function")
  // This thing can quack

To create a static property attach it to the ‘class’, not an instance.(class in quotes cause in Js they’re all objects.)
Example with a Person ‘class’:

function Person(){
Person.staticProperty = 2;

Nothing’s ever constant, but you can use conventions like ALL_CAPS to show that certain values should not be modified.


Function’s parents can return and get garbage collected, but if the child function still exists it will still be able to see all of the variables it had access to when the parent was alive.

Variable declarations (not initializations) are hoisted to the top of their scope.
If it’s a var = function(){…} then the whole function is hoisted up.

These 2 functions are the same:

function membername(...) {...}
var membername = function membername(...) {...};

Sort an array of ints

ary.sort(function(a,b){return a-b }); //ary will be modified by sort.

Number and parseInt

//parseInt accepts base as second optional param
// parsing:
parseInt("20px"); // 20
parseInt("10100", 2); // 20
parseInt("2e1"); // 2

// type conversion
Number("20px"); // NaN
Number("2e1"); // 20, exponential notation

Number("010"); // 10
parseInt("010"); // 8, implicit octal
parseInt("010", 10); // 10, decimal radix used
But it can handle numbers in hexadecimal notation, just like parseInt:

Number("0xF"); // 15
parseInt("0xF"); //15