The 'interesting' JavaScript Types


typeof primitive types

Here lists the typeof results of primitive types:

var undefinedVariable;
var nullValue = null;
var anObject = new Object();
var func = function () { };

typeof ("string"); //result in "string"
typeof (1024); // number
typeof (true); // boolean
typeof (undefinedVariable); // undefined
typeof (anObject ); // object
typeof (undeclaredValue); // undefined
typeof (nullValue); // object
typeof (null) // object
typeof (func) // function
typeof (Object) // function

Things need to be highlighted are:

  • Both undefined and undeclared variable are of type undefined
  • Variable is null when assigned with null otherwise it will be undefined
  • Object is a function
  • null is an object, I guess it means a null object.

Read More »

Great JavaScript Interview Questions


19 Great JavaScript Interview Questions

copied from here


What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a function block?

A: This is an increasingly common practice, employed by many popular JavaScript libraries (jQuery, Node.js, etc.). This technique creates a closure around the entire contents of the file which, perhaps most importantly, creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries.

Another feature of this technique is to allow for an easily referenceable (presumably shorter) alias for a global variable. This is often used, for example, in jQuery plugins. jQuery allows you to disable the $ reference to the jQuery namespace, using jQuery.noConflict(). If this has been done, your code can still use $ employing this closure technique, as follows:

(function($) { /* jQuery plugin code referencing $ */ } )(jQuery);

Read More »

Get Website URLs via JavaScript


Copied from here

There are several ways you can do this, but one way might be best for certain situations (e.g. within an iFrame).

Protocol + Domain + Page

> ""

> ""

Protocol + Domain

> ""

> ""


> "/page1.html"

Written with StackEdit.

Read More »

Using CSS Properties to Create a Cool Button


Using CSS properties alone, recreate this button:

enter image description here

This would be a great test of the candidate’s CSS3 skills. This button is loaded with that kind of stuff. Things I would look for:

  • How did they handle multiple borders? box-shadow is probably the best way here.
  • Did they use text-transform: uppercase; for the text? That would be best.
  • How did they handle the stars? Pseudo elements would be a good candidate there. Did they use unicode? Icon font?
  • Did they catch the subtle text-shadow?
  • How did they split the background in the main part of the button? a linear-gradient with no fade would be a good technique there. Or box-shadow.
  • Were they careful with the nested border-radius?

My solution

a {
  border-radius: 4px;
  border-color : aliceblue;
  background-color: gray;
  padding: 5px;  
  text-decoration: none;
  box-shadow:0px 0px 1px 4px red,
    0px 0px 1px 8px #000000;
  text-shadow:1px 1px #00ffff;
  font-weight: bold;
  background: linear-gradient(180deg, lightgray, gray);

a:before, a:after{

The challenge/question was from here

Written with StackEdit.

Read More »

Investigate High CPU usage or Infinite Loop via WinDbg


Confirm the Issue

We can investigate it using TaskMgr, if the CPU is around 25%, 50% or 100% (depends on how many cores you have, e.g. for 4 cores, 25% mean the program used up 1 core.)

If the CPU rate is not high but the program hangs, it probably indicates a deadlock.

Find the Thread

Note: WinDbg will suspend all thread, so we need to run the g command frequently if the program has something needs to run continuously, for example the program may disconnect from the server if suspended too long.


Open WinDbg and the Command window(alt+1)

  • Attach to the process that you want to inspect using File-->Attach to a process(F6). And run g` in Command window immediately.
  • See the instructions here to setup the Symbol File Path and don’t forget to tick the reload check box. If you process cannot be suspended to long, then I would suggest just include the minimal necessary symbol files, especially you should exclude the Microsoft Symbol Server.

Read More »