Is
var myFunc = function() {
}
similar to myFunc = new function () { }
I read in the documentation it says both mean the same. What is the difference between these two?
Is
var myFunc = function() {
}
similar to myFunc = new function () { }
I read in the documentation it says both mean the same. What is the difference between these two?
They are not the same.
var myFunc = function(){}
myFunc
is a reference to anonymous function expression.var myFunc = new function (){}
reference to newly constructed instance of anonymous function expression.var myFunc = function() {}
var myFunc1 = new function() {}
// it is the same as doing:
var myFunc2 = new myFunc;
console.log(myFunc, ' and the type is ', typeof myFunc)
console.log(myFunc1, ' and the type is ', typeof myFunc1)
console.log(myFunc2, ' and the type is ', typeof myFunc2)
You can reference this answer as well