Can I have object with the same name as class in javascript?
There are no classes per se in javascript, only methods that build objects.
To directly answer your question, yes and no. You can create a function that builds your object, but as soon as you have a variable of the same name, the function is destroyed.
there is no difference between
function bob() {
//code goes here
this.name = "bob";
}
and
var bob = function() {
//code goes here
this.name = "bob";
}
What would then happen if you declared a variable named bob like:
var bob = new bob();
In this case, the function bob would be called, the object created, and the function bob clobbered by the new variable bob.
If you want to create a singleton, then you might as well use a closure as follows:
var bob = new (function() {
//code goes here
this.name = "bob";
})();
You can use the same name for class and variable, yes. But start the class with an uppercase letter and keep variable names lowercase. (Thus a class Bob and variable bob.)
Javascript is case sensitive so it knows the difference. For you, both would just read the same.