null is an object that you can use when creating variables when you don't have a value yet:
var myVal = null;
When you do this, you can also use it to check to determine if it is defined:
// null is a falsy value if(!myVal) { myVal = 'some value'; }
I would not use it as usual. It is simple enough to use 'undefined', instead:
var myVal; // this is undefined
And it still works as a false value.
Create Objects
When you create an object in javascript, I like to declare all my object properties at the top of my object function:
function myObject() { // declare public object properties this.myProp = null; this.myProp2 = null; this.init = function() { // ... instantiate all object properties }; this.init(); }
I do this because it is easier to see which properties of the object are directly on the bat.
source share