function ClassA(){
this.value = 5;
}
var obj1 = new ClassA;
var obj2 = new ClassA();
console.log(obj1.value);
console.log(obj2.value);
Both prints ‘5’ in the console. What’s the difference between both the ways (other than the inclusion of arguments for the constructor)?
The parentheses are optional – if you do not have any constructor parameters to pass, they can be omitted.
Strangely enough, semicolons are also (sometimes) optional thanks to Automatic Semicolon Insertion (source, more). This sparked a lengthy debate earlier this year and prompted a response from Douglas Crockford (JSON/JSLint inventor, JS guru).