0

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?

Karthik
  • 691
  • 1
  • 5
  • 16

1 Answers1

-1

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

Tareq
  • 5,283
  • 2
  • 15
  • 18